• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC problem:Too few parameters. Expected 1

 
Jess Ishasder
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(JdbcOdbc.java:6031)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6188)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:2494)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:334)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:249)
at ProductDesptServlet.doGet(ProductDesptServlet.java:68)
..............................
What does the error message mean?
 
Balaji C
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stelian Iancu
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this error can occur when you mispell a table name or column name(error message is misleading). Make sure that they are correct.
Jamie
 
Jess Ishasder
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help!
I've tried the one that Stelian Iancu suggested.
It worked!!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic