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 preparedStatement and setxxx(1, myxxx); 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 "preparedStatement and setxxx(1, myxxx);" Watch "preparedStatement and setxxx(1, myxxx);" New topic

preparedStatement and setxxx(1, myxxx);

Heath Lilley
Ranch Hand

Joined: Jan 09, 2001
Posts: 72
I am having trouble setting a bind variable to a (oracle 8) 2 digit number.

(The real query is rather large but it does work with '07' hard coded in place of the ?.)
Now according to the db myMonth is a NUMBER(2) type.
I tried the following:

but I get an Invalid number exception from the oracle drivers.
What do i need to call to bind a 2 digit number in a prepaired statement other than raw string concat'n?

[This message has been edited by Heath Lilley (edited January 16, 2001).]
Peter Tran

Joined: Jan 02, 2001
Posts: 783
Try setInt().
If that doesn't work, then you can try this technique.
1. Get a database connection.
2. Get the metadata object.
3. Execute a getColumns() on that table.
4. Find the correct column name and get its column type from the result set.
5. Using the column type as the type for your setXXX() statement.
[This message has been edited by Peter Tran (edited January 16, 2001).]
I agree. Here's the link:
subject: preparedStatement and setxxx(1, myxxx);