*
The moose likes JDBC and the fly likes Convert Date with to_char() in a select statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Convert Date with to_char() in a select statement" Watch "Convert Date with to_char() in a select statement" New topic
Author

Convert Date with to_char() in a select statement

Reggie McDougal
Ranch Hand

Joined: Sep 27, 2004
Posts: 69
Can anyone tell me what the correct syntax is for doing this I need to
format the date for my app, but the syntax is wrong I get a Invalid column name exception.

"SELECT product_id, product_type_id, name, description, long_description, to_char(active_from,'dd/mm/yyyy'), to_char(active_to,'dd/mm/yyyy') from product WHERE product_id = " + prodID + " and product_type_id = " + prodTypeID;

This works fine when when I run it in sql. So I think JDBC does not like it.

I'm using Oracle 8

Reg

[ January 18, 2005: Message edited by: Reggie McDougal ]
[ January 18, 2005: Message edited by: Reggie McDougal ]

You can never drink too much
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Reggie,

give alias to columns on which you are applying
to_char() and make your sql query as

"SELECT product_id, product_type_id, name, description, long_description, to_char(active_from,'dd/mm/yyyy') active_from, to_char(active_to,'dd/mm/yyyy') active_to from product WHERE product_id = " + prodID + " and product_type_id = " + prodTypeID;


then your JDBC will like it


thanks
Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
 
jQuery in Action, 2nd edition
 
subject: Convert Date with to_char() in a select statement