Solved

JDBC: how to read CHAR and DATE data

Posted on 2003-12-08
9
259 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
 
LVL 15

Expert Comment

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

char c = s.charAt(0);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
best (free) software to access postgres db (java) 1 33
bitbucket vs gitbucket 3 57
servlet  URL Rewriting 1 27
oracle 11g 23 50
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now