package testsuite.simple; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.sql.Blob; import testsuite.BaseTestCase; public class TestBug24695 extends BaseTestCase{ public TestBug24695(String name) { super(name); } //We do not actually need data in BLOB to get exception public void testBug24695() throws Exception { createTable("tblTestBug24695", "(coverimage INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, description VARCHAR(255) NULL, keywords varchar(255) NULL, data MEDIUMBLOB NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8;" ); this.stmt.executeUpdate("INSERT INTO `tbltestbug24695` (`description`,`keywords`,`data`) VALUES ('test row 1','some kw','ANYTHING')"); try { this.pstmt = conn.prepareStatement("SELECT coverimage, data FROM tblTestBug24695 WHERE coverimage = ?"); this.pstmt.setInt(1, 1); //this.pstmt.setLong(1, 1); this.rs = this.pstmt.executeQuery(); assertEquals(true, this.rs.next()); Blob imageData = null; imageData = this.rs.getBlob("data"); InputStream inStr = imageData.getBinaryStream(); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); int b; while ((b = inStr.read()) != -1) { bOut.write((byte) b); } } finally { closeMemberJDBCResources(); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub junit.textui.TestRunner.run(TestBug24695.class); } }