Bug #9040 Batched PreparedStatements with binary data fail
Submitted: 8 Mar 2005 6:44 Modified: 14 Mar 2005 17:11
Reporter: Jonathan Baxter Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:3.1.7 OS:Linux (SuSE 9.2 Pro)
Assigned to: CPU Architecture:Any

[8 Mar 2005 6:44] Jonathan Baxter
Description:
Executing a batched PreparedStatement that includes a binary column fails with the following message:

 java.sql.BatchUpdateException: Incorrect arguments to mysql_stmt_execute

This worked under 4.0. 

See attached test case. 

How to repeat:
Run this with a 4.1.10 backend (not tested on other variants of 4.1): 

import java.io.ByteArrayInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Test batch prepared statement updates. Fails on MySQL 4.1.10 /  SuSE Linux Pro 9.2.
 * 
 * @author <a href="mailto:jbaxter@panscient.com>Jonathan Baxter </a>
 */
public class MyBugReport extends com.mysql.jdbc.util.BaseBugReport
{
	private PreparedStatement preparedStatement;
	private Connection connection;

	// From BaseBugReport
	public void setUp() throws Exception
	{
		connection = getConnection();

		// create the table
		Statement statement = connection.createStatement();
		statement.executeUpdate("create table if not exists test_batch_ps "
				+ "(primary_key int not null primary key, "
				+ "data mediumblob)");

		statement.close();

		// prepare the statement
		preparedStatement = connection
				.prepareStatement("replace into test_batch_ps (primary_key, data) values(?,?)");

	}

	// FromBaseBugReport
	public void runTest() throws Exception
	{
		int primaryKey = 1;
		byte[] data = "First Row".getBytes();
		preparedStatement.setInt(1, primaryKey);
		preparedStatement.setBinaryStream(2, new ByteArrayInputStream(data),
				data.length);
		preparedStatement.addBatch();

		primaryKey = 2;
		data = "Second Row".getBytes();
		preparedStatement.setInt(1, primaryKey);
		preparedStatement.setBinaryStream(2, new ByteArrayInputStream(data),
				data.length);
		preparedStatement.addBatch();

		try
		{
			preparedStatement.executeBatch();
		}
		catch (SQLException e)
		{
			assertTrue(e.toString(), false);
		}
	}

	// From BaseBugReport
	public void tearDown() throws Exception
	{
		preparedStatement.close();
		Statement statement = connection.createStatement();
		statement.executeUpdate("drop table test_batch_ps");
		statement.close();
		connection.close();
	}

	public static void main(String args[]) throws Exception
	{
		new MyBugReport().run();
	}
}
[14 Mar 2005 17:11] Mark Matthews
This is fixed for 3.1.8. You can check out a nightly build from http://downloads.mysql.com/snapshots.php after 00:00 GMT tomorrow to test the fix before 3.1.8 is released.