JDBC: how to read CHAR and DATE data

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?

piouAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
Oops

s = s.substring(0);

0
jimmackCommented:
s = s.substring(0, 1);

;-)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

jimmackCommented:
or if you just want the "char" value:

char c = s.charAt(0);
0
CEHJCommented:
>>s = s.substring(0, 1);

Yes - not woken up properly yet ;-)
0
jimmackCommented:
Same thing I did with JList.add() last night ;-)
0
CEHJCommented:
Not that it would have done you much good if you *had* got it right - for obvious reasons ;-)
0
piouAuthor Commented:
My worry about CHAR is implications when reading/writing using international locales. Anyway, by trial and error I guess :)  Thanks.
0
CEHJCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.