File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC problem:Too few parameters. Expected 1" Watch "JDBC problem:Too few parameters. Expected 1" New topic
Author

JDBC problem:Too few parameters. Expected 1

Jess Ishasder
Greenhorn

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(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

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
Greenhorn

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.
Jamie
Jess Ishasder
Greenhorn

Joined: Feb 19, 2002
Posts: 21
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
 
subject: JDBC problem:Too few parameters. Expected 1
 
Similar Threads
select works in db, but not across jdbc...
Retreiving data
Insert Query Not working
Problem With Inserting
Passing data from text file to table.