Import java. SQL .*;
Import java. Io .*;
Public class writedb {
Public static void main (string [] ARGs ){
Connection conn = NULL;
String driver = "com. MySQL. JDBC. Driver"; // driver
String url = "JDBC: mysql: // 127.0.0.1/test? Useunicode = true; characterencoding = 8859_1 "; // database connection
Try {
Class. forname (driver). newinstance ();
Conn = drivermanager. getconnection (URL, "root ","");
File file = new file (ARGs [0]);
Fileinputstream FCM = new fileinputstream (File );
Preparedstatement pstmt = conn. preparestatement (
"Insert into picture (picture) values (?) ");
Int bytes = (INT) file. Length ();
System. Out. println (bytes );
Pstmt. setbinarystream (1, FS, bytes); // 1 indicates the inserted parameter 1, 2... Fileinstream is the inserted data, and bytes is the byte length.
Pstmt.exe cuteupdate ();
Conn. Close ();
FCM. Close ();
} Catch (exception e ){
System. Out. println (E. getmessage ());
}
}
}