• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid Arguments

 
James Pozenel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am using Access2000 and JDBC to update a record. I am using a PreparedStatement in order to pass new values to the DB.
public static String UPDATE_BUILDER = "UPDATE BuilderInfo SET BuilderName ='?', Address='?', City='?', State='?', Zip=?, " +"Phone='?', Fax='?', Pager/Cell='?', ContractorName ='?', ContactName='?' WHERE BuilderID =?";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, userid, passwd);
PreparedStatement stmt = conn.prepareStatement(UPDATE_BUILDER);
stmt.setString(1, bName);
stmt.setString(2, bAddress);
stmt.setString(3, bCity);
stmt.setString(4, bState);
stmt.setLong(5, Long.parseLong(bZip));
stmt.setString(3, bPhone);
stmt.setString(3, bFax);
stmt.setString(3, bMobile);
stmt.setString(3, bOwnerName);
stmt.setString(3, bCName);
stmt.setLong(5, Long.parseLong(bID));
stmt.executeUpdate();
Right before the stmt.setString(3, bCity); the program experiences a SQL error as follows:
Error - java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid argument value
What's wrong? Is it the code or Access? Any insight on this matter would be greatly appricated.
Thanks,
James
 
Robert Brunner
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you keep setting the third parameter in the prepared statement? The setString() method should be setting different parameters.
 
James Pozenel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my bad I cut and pasted the line and forgot to change the parameter numbers.
s/b
stmt.setString(1, bName);
stmt.setString(2, bAddress);
stmt.setString(3, bCity);
stmt.setString(4, bState);
stmt.setLong(5, Long.parseLong(bZip));
stmt.setString(6, bPhone);
stmt.setString(7, bFax);
stmt.setString(8, bMobile);
stmt.setString(9, bOwnerName);
stmt.setString(10, bCName);
stmt.setLong(11, Long.parseLong(bID));
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you must get rid of the single quotes. You do not need them around string value parameters:
public static String UPDATE_BUILDER = "UPDATE BuilderInfo SET BuilderName =?, Address=?, City=?, State=?, Zip=?, " +"Phone=?, Fax=?, Pager/Cell=?, ContractorName =?, ContactName=? WHERE BuilderID =?";
Jamie
...didn't I already suggest this yesterday??
 
James Pozenel
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you did in the JDC website. The suggested fix gives a [ODBC Driver Manager] syntax error. This was also posted on the JDC forum today
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have heard of problems with using prepared statements and MSAccess so try it as a statement again:

if it still does not work, cut and paste the System.out.println(UPDATE_BUILDER) printed out line into the MSAcces SQL Editor and try to run the SQL statement directly from Access.
Jamie
[This message has been edited by Jamie Robertson (edited August 10, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic