aspose file tools*
The moose likes JDBC and the fly likes JDBC problem:Too few parameters. Expected 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC problem:Too few parameters. Expected 1" Watch "JDBC problem:Too few parameters. Expected 1" New topic

JDBC problem:Too few parameters. Expected 1

Jess Ishasder

Joined: Feb 19, 2002
Posts: 21
What's wrong with my statement?
String prdID = "a111";
String sql = "Select * " +
"from Prd_Cat " +
"where PID = " + prdID;
rs = stmt.executeQuery(sql);
My database connection is no problem, I can execute other sql statements. However, when I executed the above statment , an error message is generated:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(
at sun.jdbc.odbc.JdbcOdbc.standardError(
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(
at sun.jdbc.odbc.JdbcOdbcStatement.execute(
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(
at ProductDesptServlet.doGet(
What does the error message mean?
Balaji C

Joined: Mar 05, 2002
Posts: 1
Some time we might have missed space between "select *" and "from Prd_Cat" since these two are typed in diff lines. So just print the query in the out.println(sql). This will print the query in either in the page or in the html. Copy the query and paste the same in the SQL * Plus. There it will exactly point out the place where you did the mistake. I could not able to answer this question because I did not have any infornation about your table.
Hope this helps
[ March 05, 2002: Message edited by: Balaji C ]

Regards,<br />Balaji. C
Stelian Iancu

Joined: Feb 20, 2002
Posts: 21
Try using a PreparedStatement instead:
String sql = "Select * " +
"from Prd_Cat " +
"where PID = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, prID);
rs = ps.executeQuery();
And see what happens.

--<br />Linux registered user 287835<br /> <br />Be different. Think.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

this error can occur when you mispell a table name or column name(error message is misleading). Make sure that they are correct.
Jess Ishasder

Joined: Feb 19, 2002
Posts: 21
Thank you for your help!
I've tried the one that Stelian Iancu suggested.
It worked!!!
It is sorta covered in the JavaRanch Style Guide.
subject: JDBC problem:Too few parameters. Expected 1