Data | database
Import java.sql.*;
Import java.io.*;
public class Writedb {
public static void Main (string[] args) {
Connection Conn=null;
String driver= "Com.mysql.jdbc.Driver";//Drive
String url= "jdbc:mysql://127.0.0.1/test?useunicode=true;characterencoding=8859_1";//Database Join
try{
Class.forName (Driver). newinstance ();
Conn=drivermanager.getconnection (URL, "root", "");
File File=new file (Args[0]);
FileInputStream fis=new fileinputstream (file);
PreparedStatement Pstmt=conn.preparestatement (
"INSERT into the picture (picture) values (?)");
int bytes= (int) file.length ();
System.out.println (bytes);
Pstmt.setbinarystream (1,fis,bytes);//1 for inserted parameters 1, 2 ... Fileinstream for inserted data, bytes for byte length
Pstmt.executeupdate ();
Conn.close ();
Fis.close ();
}catch (Exception e) {
System.out.println (E.getmessage ());
}
}
}