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();
}
}