| Bug #5375 | Put Some Big File to BLOB is error | ||
|---|---|---|---|
| Submitted: | 2 Sep 2004 18:56 | Modified: | 7 Sep 2004 22:11 |
| Reporter: | Liu Naijia | Email Updates: | |
| Status: | Can't repeat | Impact on me: | |
| Category: | Connector / J | Severity: | S1 (Critical) |
| Version: | 3.1.3-beta | OS: | Any (Any) |
| Assigned to: | CPU Architecture: | Any | |
[7 Sep 2004 22:09]
Eric Herman
I couldn't repeat this error with Connector/J 3.1.4
newConn = DriverManager.getConnection(url, "root", "");
stmt0 = newConn.createStatement();
stmt0.executeUpdate("DROP TABLE IF EXISTS testBug5375");
stmt0.executeUpdate("CREATE TABLE testBug5375"
+ "(pk INT NOT NULL PRIMARY KEY, blobField BLOB)");
String sql = "insert into testBug5375 values(?,?)";
int blobFileSize = (int) (1.5 * 1024 * 1024); // 1.5MB
File blobFile = newTempBinaryFile("Bug5375", blobFileSize);
PreparedStatement stmt1 = newConn.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
stmt1.setInt(1, 2);
FileInputStream str = new FileInputStream(blobFile);
stmt1.setBinaryStream(2, str, -1);
stmt1.execute();
str.close();
stmt1.close();
-----------------------------------
private File newTempBinaryFile(String name, int size) throws IOException {
File tempFile = File.createTempFile(name, "tmp");
tempFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
for (int i = 0; i < size; i++) {
bos.write((byte) i);
}
bos.close();
assertTrue(tempFile.exists());
assertEquals(size, tempFile.length());
return tempFile;
}
[8 Sep 2004 0:32]
Liu Naijia
Olny some files are not put into BLOB fileds.Please test file "mysql-connector-java-3.1.3-beta.zip"
[8 Sep 2004 0:40]
Liu Naijia
I find you must use "useUnicode=true&characterEncoding=GBK" in url then you can find the error.
[8 Sep 2004 1:35]
Eric Herman
The url I use is:
String url = "jdbc:mysql:///test"
+ "?useUnicode=true&characterEncoding=GBK";
I would like to know if you see the problem if you adapt the test case I provided.
[8 Sep 2004 1:55]
Liu Naijia
the test case which used "useUnicode=true&characterEncoding=GBK" is good. but some files such as mysql-connector-java-3.1.3-beta.zip can't work
[8 Sep 2004 16:58]
Eric Herman
I don't happen to have a copy of the 3.1.3-beta.zip handy. However, the following change made no difference:
---------------
//File blobFile = newTempBinaryFile("Bug5375", blobFileSize);
File blobFile = new File("/home/eric/dload/zip/mysql-connector-java-3.1.4-beta.zip");
---------------
Liu, does a test case using the "newTempBinaryFile" fail for you?
[9 Sep 2004 1:01]
Liu Naijia
Your url is "useUnicode=true&characterEncoding=GBK" and your database character is gbk? I test your application. It can run.I change url to "jdbc:mysql:///test",It can run.But I must use characterEncoding=GBK,it can not run.I'm puzzled.
[9 Sep 2004 1:05]
Liu Naijia
I'm sorry. I didn't say clearly. Your program which is used tempfile can run at all time. My Program which is used 'mysql-connector-java-3.1.3-beta.zip' can not run when url is 'jdbc:mysql:///test/useUnicode=true&characterEncoding=GBK'

Description: I put mysql-connector-java-3.1.3-beta.zip to BLOB field, the program throw exception : java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '辤y^WZ璝H?晤&k?? 6螡?#?3Oi\\lw鑷盦)証懃s?<霍/???f憣?u艎杢姮k?;釉貑?' at line 1" at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2746) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1532) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622) at com.mysql.jdbc.Connection.execSQL(Connection.java:2278) at com.mysql.jdbc.Connection.execSQL(Connection.java:2204) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1777) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1413) at net.youngcow.mysql.MysqlLob.main(MysqlLob.java:35) How to repeat: my program : public static void main(String[] args) { try { String url = "jdbc:mysql://ip/db?useUnicode=true&characterEncoding=GBK"; String sql = "insert into blobtest values(?,?)"; DriverManager.registerDriver(new com.mysql.jdbc.Driver()); Connection conn = DriverManager.getConnection(url,"root",""); PreparedStatement stmt1 = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt1.setInt(1,2); FileInputStream str=new FileInputStream("D:\\mysql-connector-java-3.1.3-beta.zip"); stmt1.setBinaryStream(2,str,-1); stmt1.execute(); str.close(); stmt1.close(); conn.close(); } catch (Exception e) { Logger.Log(Logger.LOG_ERROR, e); } }