Bug #10639 UPDATE sql using PreparedStatement fails ("No value specified for parameter 1")
Submitted: 14 May 2005 14:23 Modified: 14 May 2005 14:44
Reporter: [ name withheld ] Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:mysql-connector-java-3.1.8 OS:Windows (Windows 2000 pro)
Assigned to: Mark Matthews CPU Architecture:Any

[14 May 2005 14:23] [ name withheld ]
Description:
I use mysql-connector-java-3.1.8-bin and MySql 5.0.19.
When I use PreparedStatement class, I manage to do INSERT & DELETE queries, but when trying to an UPDATE query, I get 
 "java.sql.SQLException: No value specified for parameter 1".

The exception is thrown when commiting "executeUpdate()".

I'm sure my code is fine because the PreparedStatement.toString() looks fine (see below).
If I use the sql the "toString()" method shows, with a regular Statement, it works fine.

+  I got the same error when using my previous driver (3.0.11).
+  Null values were not invlove in this exception.

Here is my PreparedStatement "toString()":
---------------------------------------------------
"com.mysql.jdbc.PreparedStatement@2b323e: UPDATE books SET
book_id=2,quantity=4 WHERE book_id=2"

Here is the Stack Trace:
----------------------------
com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2059)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1945)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1897)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1758)
database.editor.DataAccess.updateRecords(DataAccess.java:447)
database.editor.DataAccess.updateDatabase(DataAccess.java:377)
database.DBEditor.saveGridStatus(DBEditor.java:385)
database.DBEditor.actionPerformed(DBEditor.java:250)
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
java.awt.Component.processMouseEvent(Component.java:5100)
java.awt.Component.processEvent(Component.java:4897)
java.awt.Container.processEvent(Container.java:1569)
java.awt.Component.dispatchEventImpl(Component.java:3615)
java.awt.Container.dispatchEventImpl(Container.java:1627)
java.awt.Component.dispatchEvent(Component.java:3477)
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
java.awt.Container.dispatchEventImpl(Container.java:1613)
java.awt.Window.dispatchEventImpl(Window.java:1606)
java.awt.Component.dispatchEvent(Component.java:3477)
java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

How to repeat:
1. Build a PreparedStatement to the current database table in use.

2. Set its (UPDATE Statement) question marks (parameters) in the following way:
  2.1 For each table column in the SET part (c1=?, c2=?, cN=?)
  2.2 For each table Primary Key column in the WHERE part.

(e.g. "Update books SET c1=?, c2=? WHERE c1=?", when c1 is a PK column)

3. Fill this parameters with proper values.

4. Execute the preparedStatement by committing "PreparedStatement.executeUpdate()".
[14 May 2005 14:44] Mark Matthews
Unfortunately I'm not able to reproduce this with the information given. I've tried update statements similar to the one you've given, and no error is produced.

Without information about your table structure, and the _exact_ Java code you're using, we can't proceed in debugging this any further.

If you can, please make a standalone testcase that demonstrates the behavior, which includes code for creating the table(s) in question, creates the prepared statement and execute()s it.
[15 May 2005 17:50] [ name withheld ]
I'm sorry. I was wrong, I did a standalone test and it worked. The (silly) bug was on my side.
Thanks for the quick reply.