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 dont know y it occurs Exception: Too few arguments. Expected 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "dont know y it occurs Exception: Too few arguments. Expected 2" Watch "dont know y it occurs Exception: Too few arguments. Expected 2" New topic
Author

dont know y it occurs Exception: Too few arguments. Expected 2

Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
i m using access data base.. and following table i created..
1. chater
fields. user_id int,nick string,status int
2. buddys
fileds. id int,buddy_id int ,status int
here is my simple query String
String q1 = "select b.*,c.nick from buddylist b,chater c where b.id=? "+
"and b.buddy_id=c.user_id";
i use this same query on hsql managar its work fine but in my class it gives above error.
also if i write a query to fatch record from single table its work fine but in join condition it gives above error.. i dont know how to takle this error plesae help..
thanks in advance
Qasim Shabbir
SCJP
Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
Sorry! its not "too few arguments" instead the complete detail of error are:
DBConnection:getBuddyList roblem in query :
java.sql.SQLException: [Microsoft][O
DBC Microsoft Access Driver] Too few parameters. Expected 1.
i m useing Statement object to fire a query.
Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
Sorry! its not "too few arguments" instead the complete detail of error are:
DBConnection:getBuddyList roblem in query :
java.sql.SQLException: [Microsoft][O
DBC Microsoft Access Driver] Too few parameters. Expected 1.
i m useing Statement object to fire a query.
QASIM
SCJP
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Qasim:
I don't understand why there is a question mark in your query ( where b.id=? ) when you are using a statement and not a prepared statement? how do you set that value before it is executed?
Also, try replacing b.* with the actual column names. I have seen this error occur when a column or table is mispelled, and maybe your driver doesn't know how to handle the * as a valid column name.
Jamie
Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
hi thnx for replying..
actuly first i use.. prepared statement its throws "Too few Parameter expected 2. there after i use Statment then its throws "...Expected 1"
also as per yr suggestion i use complete table name and write complete field name instead of *.
but the error is same.. it work fine on single table query but again on join condition it throws error.
Qasim Shabbir
SCJP
Tina Coleman
Ranch Hand

Joined: Dec 12, 2001
Posts: 150
In using the statement, you'd just set up your statement as:

You use the question marks in the PreparedStatement as placeholders. Not applicable in Statement. But since you say you got it working elsewhere. . .
Can you post the code you're using to create your statement? Something's niggling at the back of my brain that I've run into that same error - hoping that seeing your code would trigger it again for me.
[ November 21, 2002: Message edited by: Tina Coleman ]
Mark Howard
Ranch Hand

Joined: Feb 14, 2001
Posts: 285
I've come across this problem before, and it usually had something to do with the way in which the query was set up rather than the contents of the query itself. Best thing is to post your code as Tina suggested.
Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
here is the method which cozing exception..
i use jdbcodbc birdge for acess database.

public Vector getBuddyList(int userId){
Statement statement;
String query="select buddylist.*, chater.nick from buddyList, chater where buddylist.id="+userId+" and chater.user_id=buddylist.buddy_id ";
Vector buddyList=new Vector();
try{
statement=connection.createStatement();
System.out.println("DBConnection:getBuddyList:query ="+query);
ResultSet rs=statement.executeQuery(query);
System.out.println("DBConnection:getBuddyList: executed :");
while(rs.next ()){
Buddy buddy=new Buddy();
buddy.setBuddyId (rs.getInt("buddy_id"));
buddy.setId (rs.getInt("id"));
buddy.setBlock (rs.getByte("isblock"));
buddy.setStatus (rs.getByte("status"));
buddyList.addElement(buddy);
}
return buddyList;
}catch(SQLException sql){
String errorMessage=
"DBConnection:getBuddyList roblem in query :"+sql;
System.out.println(errorMessage);
}
return null;
}
Qasim Shabbir
SCJP
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

don't know if this will make a difference but you use both buddyList and buddylist as your table name/qualifiers. Make them all the same, including capitalization. This would be related to my experience with this same error message that was caused by incorrect spelling of a column/table name.
Otherwise, all looks fine.
Jamie
PS, when you successfully ran the query through HSQL query analyzer, did you cut and paste the statement from your java output or just type in the same query to the editor?
Qasim Shabbir
Greenhorn

Joined: May 12, 2002
Posts: 16
thnx 4 reply robertson..
well i implement yr suggestion. but sorry to say its still not working and throwing same error..
about hsql yes i cut and paste query string there and there is no problem of capitalization..
i m using access 2000 i didnt hv any other version of access.. is there any problen in access database regarding to relation. if any body know pls reply..
QASIM SHABBIR
Tina Coleman
Ranch Hand

Joined: Dec 12, 2001
Posts: 150
Unfortunately, I don't have an Access database to try this out, but Jamie had mentioned some drivers having problems with *. You do seem to have a specific set of columns that you want to pull (buddy_id, id, isblock, status) - why not specifically reference them in your statement? This should also make for a more efficient returned ResultSet.
Just verifying: you're not getting to your 'DBConnection: getBuddyList: executed' println. . . the exception is being thrown prior to retrieving data from the ResultSet.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dont know y it occurs Exception: Too few arguments. Expected 2