• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prepared Statement - only for field values?

 
Gale Greaser
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic