aspose file tools
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply 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: 1076

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Convert Date with to_char() in a select statement
 
Similar Threads
Formating a Date not using SimpleDateFormat
URGENT : Prepared Statement Problem
Taking a getDate from an Array and
Query giving me two different results
JDBC - Date