Wrote a quick example to check this locally with MySQL (sorry for the incorrect exception handling):
public void testInputStream(String filePath) throws SQLException, IOException {
DBUtil util = new DBUtil();
Connection conn = util.getConnection("test");
conn.setAutoCommit(false);
File file = new File(filePath);
FileInputStream fis = null;
fis = new FileInputStream(file);
String sql = "insert into testtable(scol,lob) values(?,?)";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, "number4!");
stmt.setBlob(2, fis);
stmt.executeUpdate();
fis.close();
conn.commit();
stmt.close();
}
testtable is a very simple table:
create table testtable (
id int auto_increment primary key,
scol varchar(50),
lob blob
)engine=innodb;
, , . , , , , InputStream . MySQL PreparedStatement ; , sendPacket() ( , ), executeUpdate() .
, , , JDBC. , InputStream, .