This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes pass TO_DATE to preparestatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "pass TO_DATE to preparestatement" Watch "pass TO_DATE to preparestatement" New topic
Author

pass TO_DATE to preparestatement

pavan sharma
Greenhorn

Joined: Dec 19, 2006
Posts: 21
Hi,

PG_DATE is date field in master table in oracle database.

I want to set it with preparedstatement like -

pstmt.setString(4,TO_DATE(PG_DATE,"DD-MM-YYYY"));


it gives error -

symbol : method TO_DATE(java.lang.String,java.lang.String)
location: class dbbean.addcontentbean
pstmt.setString(4,TO_DATE(PG_DATE,"DD-MM-YYYY"));

how can i pass it with preparedstatement.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Why don't you call pstmt.setDate instead ?

If you still want to pass a string, use TO_DATE into your sql statement:
INSERT INTO MYTABLE VALUES ( TO_DATE(?, 'DD-MM-YYYY'), .... )
[ January 22, 2007: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by pavan sharma:

it gives error -
symbol : method TO_DATE(java.lang.String,java.lang.String)
location: class dbbean.addcontentbean
pstmt.setString(4,TO_DATE(PG_DATE,"DD-MM-YYYY"));


its because compiler didn't found any function defined by name TO_DATE in addcontentbean class. its a SQL function so you must define your SQL related things in your SQL Query as Satou defined in a SQL statement.

how can i pass it with preparedstatement.

In preparedStatment SetXXX Method only takes 2 parameter one is value and another its(value) bound location.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Your question is not at all related with JSP. Please select the right forum before posting your query..

Suggestion
JDBC forum would be better place to asking JDBC related question..
[ January 22, 2007: Message edited by: Saif uddin ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Saif uddin:

Suggestion
JDBC forum would be better place to asking JDBC related question..


Which is where this thread can now be found.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pass TO_DATE to preparestatement