| Bug #10850 | setCharacterStream with empty stream results in exception | ||
|---|---|---|---|
| Submitted: | 25 May 2005 2:10 | Modified: | 6 Jun 2005 23:03 |
| Reporter: | Chris Wood | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / J | Severity: | S2 (Serious) |
| Version: | 3.1.8 | OS: | |
| Assigned to: | CPU Architecture: | Any | |
[25 May 2005 2:11]
Chris Wood
The test case.
Attachment: Blah.java (application/octet-stream, text), 1.43 KiB.
[25 May 2005 7:50]
Vasily Kishkin
Tested on Win 2000 Sp4 , JDK 1.5, MyODBC 3.51.11. Test case is attached.
[25 May 2005 7:50]
Vasily Kishkin
Test case
Attachment: test.java (text/plain), 1.54 KiB.
[25 May 2005 7:52]
Vasily Kishkin
Sorry. I did't see Chris's suit case and created mine.
[6 Jun 2005 23:03]
Mark Matthews
Fixed for 3.1.9. See the nightly snapshots at http://downloads.mysql.com/snapshots.php#connector-j
[1 Sep 2005 19:57]
Ralf Hauser
Somehow, this still appears to appear?
stmt.setBinaryStream(4, new ByteArrayInputStream("".getBytes()),
causes
<<DEBUG [http-8443-Processor23] (DBSystem.java:1666) - (DBSystemGenericImpl.addAttachment:703) - com.mysql.jdbc.ServerPreparedStatement[294] - INSERT INTO TBL_ATTACHMENT (file_size, file_name, content_type, file_data_blob, create_id, create_date) VALUES (23,'a-1.txt','image/gif', ** STREAM DATA ** ,144,'2005-09-01 21:53:04' )
java.sql.SQLException: Incorrect arguments to mysql_stmt_execute
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1366)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:952)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1974)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1897)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1758)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
at com.privasphere.privalope.db.DBSystemGenericImpl.addAttachment(DBSystemGenericImpl.java:708)
>>
I use mysql-connector-java-3.1.10-bin.jar with jdk1.5 on redhat Linux 2.6.9-11.EL #1 Fri May 20 18:17:57 EDT 2005 i686 i686 i386 GNU/Linux with the server version 4.1.13-standard-log
[1 Sep 2005 20:18]
Ralf Hauser
stmt.setBinaryStream(4, new ByteArrayInputStream("a".getBytes()), 0);
fixed it for me.
correct would probably have been
stmt.setBinaryStream(4, new ByteArrayInputStream("a".getBytes()), 1);
(I do later update the blob with the big stream - this way the code also works for oracle)

Description: Attempting to use the setCharacterStream with a zero length stream for text fields results in an exception. This was working in 3.1.6 but fails in 3.1.8. Use the test case to replicate. This failure only occours when both the string and the length are zero, if the input stream is greater than zero length the exception doesn't occour, even when the length value is zero. How to repeat: The Code: Connection conn = null; Statement batch = null; PreparedStatement stmt = null; try { conn = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "root"); batch = conn.createStatement(); batch.addBatch("drop table if exists TEXT_COLUMN"); batch.addBatch( "create table TEXT_COLUMN (" + " path text not null" + ") engine=InnoDB"); batch.executeBatch(); stmt = conn.prepareStatement("insert into TEXT_COLUMN (path) values (?)"); stmt.setCharacterStream(1, new StringReader(""), 0); // failure here stmt.executeUpdate(); } finally { if(stmt != null) stmt.close(); if(batch != null) batch.close(); if(conn != null) conn.close(); } Exception: java.sql.SQLException: Incorrect arguments to mysql_stmt_execute at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531) at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1366) at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:952) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1974) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1897) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1758) at Blah.jdbcTest(Blah.java:46) at Blah.main(Blah.java:16)