This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes SQL built-in functions in PreparedStatement? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL built-in functions in PreparedStatement?" Watch "SQL built-in functions in PreparedStatement?" New topic
Author

SQL built-in functions in PreparedStatement?

Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85
This kind of a PreparedStatement is throwing an exception..



I have never tried anything like this before,.. but curious to know if this is ok..or not..?? I appreciate your help..
At the same time, i'll also see what the cause of the exception is..

Thanks again
[ August 04, 2005: Message edited by: Bear Bibeault ]
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
What exception is it throwing? Can you please submit that so that we can know the exact problem.

Personally i feel the PreparedStatement is creating the problem
INSERT INTO LIBRARYNAME.TABNAME VALUES (?,?,?,?,TIME(?),TIME(?),?,?,?,NOW(),?)

Regards
Makarand Parab
Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85



I am actually using DB2 UDB.. some casting issue.. !!..

Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Hi
That exception is because
INSERT INTO LIBRARYNAME.TABNAME VALUES (?,?,?,?,TIME(?),TIME(?),?,?,?,NOW(),?)
is not allowed
it should be
INSERT INTO LIBRARYNAME.TABNAME VALUES (?,?,?,?,?,?,?,?,?,?,?)
and then pass the value.

Regards
Makarand Parab
Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85
ohh ok.. I am just curious to see if i can do that..
and if it is possible to include SQL built-in functions in
the prepared stmt

Anyway thanks
Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85
Just to mention:

INSERT INTO LIBRARYNAME.TABNAME VALUES (?,?,?,?,?,?,?,?,?,NOW(),?)

The above Works fine... No problem.. The Time fields i am sending
java.sql.Time values..

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Antonio,
When you call TIME(?), are you still passing it a java.sql.Time object? If so, this would explain the casting error. TIME() coverts a var char to a time and therefore expects a String.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Antonio Giovanni
Ranch Hand

Joined: Jun 27, 2005
Posts: 85
Jeanne,

well when i am calling TIME(?), i am actually passing a String value.

Anyway atleast it confirmed to me that i can indeed call SQL built-in functions in PreparedStatement, that was my main question, since it allowed me calling a NOW() function.

Probably the TIME() was giving error because of some casting issue.. maybe it should be like CAST(? AS TIME). I will try this sometime today or in the week-end

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL built-in functions in PreparedStatement?
 
Similar Threads
does OracleDriver really precompile a PreparedStatement?
Variable column name in PreparedStatement
preparedStatement.setDate and java.util.Date
Doubt about PreparedStatement
MySQL Syntax Exception