wood burning stoves 2.0*
The moose likes JDBC and the fly likes Invalid Arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid Arguments" Watch "Invalid Arguments" New topic
Author

Invalid Arguments

James Pozenel
Greenhorn

Joined: Aug 09, 2001
Posts: 3
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

Joined: Jul 18, 2001
Posts: 49
Why do you keep setting the third parameter in the prepared statement? The setString() method should be setting different parameters.
James Pozenel
Greenhorn

Joined: Aug 09, 2001
Posts: 3
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: Aug 09, 2001
Posts: 3
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

Joined: Jul 09, 2001
Posts: 1879

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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invalid Arguments