public void putimg() {
Statement stmt = null;
PreparedStatement pstmt = null;
Connection conn = null;
String sql = "";
try {
File file = new File(
"D:\\storestylepics\\wallpaper4_small.png");
InputStream photoStream = new FileInputStream(file);
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url = "jdbc:mysql://10.110.100.168/appmall?user=appmall&password=appmall&useUnicode=true&characterEncoding=utf-8";
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
// sql = " UPDATE imgt SET img = ? ";
sql = "INSERT INTO am_blob_container(bigobject) VALUES (?)";
pstmt = conn.prepareStatement(sql);
// 关键在这里
pstmt.setBinaryStream(1, photoStream, (int) file.length());
pstmt.executeUpdate();
System.out.println("putimg()========end");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (pstmt != null) {
pstmt.close();
pstmt = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}