public void insertDB() throws FileNotFoundException,ClassNotFoundException,
IllegalAccessException, InstantiationException, SQLException {
String filePathFrom = "D://my.jpg" ;
File file = new File(filePathFrom);
FileInputStream fis = new FileInputStream(file);
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/test?user=root&password=";
Connection conn = DriverManager.getConnection(url);
String sql = "insert into user(id,image) values(?,?)";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setInt(1,88);
stmt.setBinaryStream(2,fis,(int)file.length());
stmt.executeUpdate();
conn.close();
System.out.println("ok0");
}
IllegalAccessException, InstantiationException, SQLException {
String filePathFrom = "D://my.jpg" ;
File file = new File(filePathFrom);
FileInputStream fis = new FileInputStream(file);
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://localhost:3306/test?user=root&password=";
Connection conn = DriverManager.getConnection(url);
String sql = "insert into user(id,image) values(?,?)";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setInt(1,88);
stmt.setBinaryStream(2,fis,(int)file.length());
stmt.executeUpdate();
conn.close();
System.out.println("ok0");
}