aspose file tools*
The moose likes JDBC and the fly likes Prepared Statement - only for field values? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Prepared Statement - only for field values?" Watch "Prepared Statement - only for field values?" New topic
Author

Prepared Statement - only for field values?

Gale Greaser
Greenhorn

Joined: Aug 05, 2002
Posts: 17
Hello -
I am having problems setting values for my prepared statement (below).

psViewLogIncrement = conn.prepareStatement(
SELECT TOP ? * FROM Log WHERE (record_id >=(SELECT MAX(record_id)FROM (SELECT TOP ? * FROM Log ORDER BY record_id) nextRecords)) ORDER BY record_id
);
psViewLogIncrement.setInt(1, 2);
psViewLogIncrement.setInt(2, 2);

The values I would like to set are not data field values, but the number of values I would like the Select to return. The error I'm getting is:
"java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s)."

Can anybody help?
Thanks in advance!
Gale.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1132

Hi Gale,
Unfortunately, you cannot put a place holder (i.e. question-mark ["?"]) anywhere you want to, in a "PreparedStatement" -- and that is what you are trying to do -- hence the "Invalid parameter bindings" error message you are receiving.
You could do something like this:
[Note: Only a suggestion]

Good Luck,
Avi.
Gale Greaser
Greenhorn

Joined: Aug 05, 2002
Posts: 17
Ahh ha!
I actually did what you had suggested and used a "Statement" instead of a "PreparedStatement".
Thanks so much for your reply - much appriciated!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prepared Statement - only for field values?