• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

identify resultset modified by the database.

 
Chuan Ren
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found that I could do this in Oracle 9i:
SELECT to_char(mystarttime, 'HH:MI PM') from TIMER_TABLE;
The database will return the time in preset format. i.e. 12:00 PM.
My question is how can I utilise this in my JSP resultset?
The following is ok:
String sql = "SELECT * FROM TIMER_TABLE";
ResultSet rset = CM.executeQuery(sql);
while (rset.next()){
out.println(rset.getDate(mystarttime));
}
getString : 2004-12-18 12:00:00.0
getDate : 2004-01-12
getTime : 12:00:00

This of course does not work:
String sql = "SELECT to_char(mystarttime, 'HH:MI PM') FROM TIMER_TABLE";
ResultSet rset = CM.executeQuery(sql);
How do I get the result processed by oracle from a Java resultset?
Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just why this was posted in JSP is beyond me. I'm moving it along to the JDBC forum for you.
bear
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chuan,
That query should work. JDBC can do anything that you can do at the command line. I think you are getting the error because the returned column doesn't have a name. Try using rs.getString(1) instead of the column name. Or you can try
toChar(field) as 'column'
fyi - You can format the data in java using the SimpleDateFormat class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic