Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JDBC: how to read CHAR and DATE data

Posted on 2003-12-08
9
261 Views
Last Modified: 2010-08-05
What is the best way to read Oracle's CHAR data? I don't think there is a relevant ResultSet method... Would it be a getString? (If so, is it guaranteed that the string is of length==1?)

Also, when getting a java.sql.Date value, how can I put it in a java.util.Date?

0
Comment
Question by:piou
  • 5
  • 3
9 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 9895525
getString is fine. You can make the String have length one come what may

if (s !=null && s.length() > 1)
    s = s.substring(1);

You can simply cast a sql Date to its supertype (java.util.Date)

java.util.Date d = (java.util.Date)_d;
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9895530
Oops

s = s.substring(0);

0
 
LVL 15

Expert Comment

by:jimmack
ID: 9895532
s = s.substring(0, 1);

;-)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 15

Expert Comment

by:jimmack
ID: 9895540
or if you just want the "char" value:

char c = s.charAt(0);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9895569
>>s = s.substring(0, 1);

Yes - not woken up properly yet ;-)
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9895587
Same thing I did with JList.add() last night ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9895597
Not that it would have done you much good if you *had* got it right - for obvious reasons ;-)
0
 

Author Comment

by:piou
ID: 9895722
My worry about CHAR is implications when reading/writing using international locales. Anyway, by trial and error I guess :)  Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9895732
8-)

It's the field in the db you should be concerned about, not Java. You should be able to store stuff in the db as Unicode. Java will handle it thereafter.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
type mismatch (Object[] to double[] 4 33
by zero exception 10 52
Java: The Public Class Main 4 32
ejb entity bean example issue 2 16
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question