Solved

Question about ResultSet.getString(String columnName)

Posted on 2004-09-28
8
951 Views
Last Modified: 2008-02-01
Hi, experts,
 
I have a sql select sentence:
    select to_char(sysdate, 'FMMonth DD, YYYY') today_month_dd_yyyy from dual
The result is
    'September 28, 2004'

But when I use java.sql.ResultSet (in a server application in Weblogic812) to get the today_month_dd_yyyy value, the java code:
    rset.getString("today_month_dd_yyyy");
always return
    9? 28, 2004

Why? Can someone help me to fix this.

Thanks in advance.
0
Comment
Question by:acanuva
8 Comments
 
LVL 12

Expert Comment

by:Giant2
ID: 12167693
why you not use Calendar.getInstance() instead?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12167694
What's the column type in your database? Is the date stored as a string or a date?
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12167704
Do you really simply want the current day?
What about:
System.out.println( (new SimpleDateFormat("MMMM DD, yyyy")).format(new Date()) );
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 12168099
Just leave the DB column as date and format it on the java side.
EX.
  select SYSDATE "txnDate" from dual
...

  SimpleDateFormat format=new SimpleDateFormat("MMMMM dd, yyyy");
  Date dt=rs.getTimestamp("txnDate");
  String dateStr=format.format(dt);
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 9

Accepted Solution

by:
Venci75 earned 500 total points
ID: 12168104
What happens if you first change the language of your session:
ALTER SESSION SET NLS_LANGUAGE = 'laguage'
0
 
LVL 1

Expert Comment

by:KartikShah
ID: 12168271
One question, are you using the native drivers provided by oracle or the ones supplied by Weblogic. the reason is that since you are doing a to_char, it should not matter to driver to display text as date. Try using this query and see thats the result:

select to_char(sysdate, '/YYYY\DD/FMMonth\') today_month_dd_yyyy from dual

and if in the java code, you get a result like:

/2004\28/September\

then there might be a problem with the driver you are using, as it might be trying to be intelligent to display the date in numericals instead of plain text.

If this works, then I suggest using the latest oracle db drivers, and verify if the issues gets resolved or no

Kartik
0
 

Author Comment

by:acanuva
ID: 12176089
Thanks very much for all answers.

Actually, I simplified my problem to get a quick answer. Let me describe it with more details.

I use jdbc to call a stored procedure which returns a ResultSet (in stored procedure, a cursor), one of the columns of the ResultSet is named 'today_month_dd_yyyy'. The definition of this column is something like:
   
    OPEN xx_cursor FOR
        SELECT DISTINCT to_char(sysdate, 'MM/DD/YYYY  HH:MI:SS A.M.') print_time,
               to_char(sysdate, 'FMMonth DD, YYYY') today_month_dd_yyyy,
               to_char(sysdate, 'MM/DD/YYYY') today_mm_dd_yyyy
                                   ......
        FROM    ......
        WHERE    ........
                   
After getting the ResultSet, I use rset.getString(columnName) to get the value of 'today_month_dd_yyyy' column. I cann't change the sql because this stored procedure is also used by other programs.

Then, comes the problem. When I test
    select to_char(sysdate, 'FMMonth DD, YYYY') today_month_dd_yyyy from dual
The result is
    'September 28, 2004'

But in java:
    rset.getString("today_month_dd_yyyy");
I got
    9? 28, 2004

Thanks
Acanuva
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12177024
You close the question, so I believe you solved your problem. Isn't it?
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
topping1 challenge 7 73
Starting to learn JAVA, 7 59
Java / Linux and Regular Expressions 11 71
MySQL  on Tomcat 8 30
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
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 …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

867 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