Solved

JDBC: how to read CHAR and DATE data

Posted on 2003-12-08
9
263 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
[X]
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
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This video teaches viewers about errors in exception handling.

707 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