Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JDBC: how to read CHAR and DATE data

Posted on 2003-12-08
9
Medium Priority
?
267 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 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

598 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