Solved

JDBC: how to read CHAR and DATE data

Posted on 2003-12-08
9
258 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
Comment Utility
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
Comment Utility
Oops

s = s.substring(0);

0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
s = s.substring(0, 1);

;-)
0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
or if you just want the "char" value:

char c = s.charAt(0);
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>s = s.substring(0, 1);

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

Expert Comment

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

Expert Comment

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

Author Comment

by:piou
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

744 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

15 Experts available now in Live!

Get 1:1 Help Now