File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL built-in functions in PreparedStatement?

 
Antonio Giovanni
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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

 
Makarand Parab
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33700
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Antonio Giovanni
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic