This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Prepared Statement  Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Prepared Statement  Error" Watch "Prepared Statement  Error" New topic
Author

Prepared Statement Error

Madhavan Sundararajan
Greenhorn

Joined: Jan 06, 2004
Posts: 3
Can I use a prepared statement to execute "select" queries? I get an error when I try to use it using JDBC..Here is the following error
SQL Exception from class SqlArrayTest executeStashQuery method java.sql.SQLException: ORA-01008: not all variables bound
Here is my query
"SELECT TO_CHAR(BUSINESSDAY,'YYYYMMDD'), TO_CHAR(RCV_DATE,'YYYYMMDD') FROM RCV where STOREID=?"
Pls clarify at the earliest
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Assuming that "STOREID" is an integer value, you need to make sure you call ".setInt(1, xxx);" on the prepared statement, where "xxx" is the int value you are searching on. This has to be done before you call "executeQuery()" on the prepared statement.
When you set up a prepared statement, the question marks (?) represent parameters that you will specify at execution time. For every parameter [?] in the query, you must call the appropriate setXXX() method. The error message you're getting seems to indicate that your parameter wasn't bound to a value, meaning you hadn't called "setInt()" before executing the query.
If this isn't your problem, please show us your code fragment.
[ February 18, 2004: Message edited by: Wayne L Johnson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prepared Statement Error
 
Similar Threads
so I have a sql date format I can't figure out
org.hibernate.exception.SQLGrammarException: could not execute query
SQL statement to java
Help! How to group by days and ignore the hours? 
Select date field problem