Re: "blobSendChunkSize" property does not work
Posted by: John Andrew Balandra
Date: October 17, 2012 07:41PM

Mark,

Thank you.

I tried setting "max_allowed_packet" to a higher value in my code but I keep on encountering the same errors. The only way that I can insert successfully is if I increase the "max_allowed_packet" value in the server - which in our case is a disadvantage since we're not really allowed to to change its value.

Any other ideas? When I set "useServerPrepStmts" to true, is it a requirement to create and access a prepared statment within my DB? Or is it just as straightforward just as you said -

"If you want to enable them so that you can use this parameter, you add "useServerPrepStmts=true" to enable them globally for the connection, or you can use them on a case-by-case basis by casting your connection to a com.mysql.jdbc.Connection and calling serverPrepareStatement(...) instead of prepareStatement(...)"

This is what I currently have in my code which apparently does not work:

File file = new File("C:\\apache-ant-1.8.3-bin.zip");
FileInputStream in = new FileInputStream(file);
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
Properties props = new Properties();
props.setProperty("user","user");
props.setProperty("password","password");
props.setProperty("blobSendChunkSize","1048576");
props.setProperty("maxAllowedPacket", "16581375");
props.setProperty("useServerPrepStmts","true");
java.sql.Connection con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/for_testing", props);

String query = "insert into blob_table values(?)";
com.mysql.jdbc.Connection conn = (com.mysql.jdbc.Connection)con;
PreparedStatement pstmt = conn.serverPrepareStatement(query);

pstmt.setBinaryStream(1, (InputStream) in, (int) file.length());
pstmt.executeUpdate();



Edited 3 time(s). Last edit at 10/17/2012 09:33PM by John Andrew Balandra.

Options: ReplyQuote


Subject
Written By
Posted
Re: "blobSendChunkSize" property does not work
October 17, 2012 07:41PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.