import java.sql.*;
import java.io.*;
public class WriteDB {
public static void main(String[] args) {
Connection conn=null;
String driver="com.mysql.jdbc.Driver";//驱动
String url="jdbc:mysql://127.0.0.1/test?useUnicode=true;characterEncoding=8859_1";// 数据库联接
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 picture(picture) values(?)");
int bytes=(int)file.length();
System.out.println(bytes);
pstmt.setBinaryStream(1,fis,bytes);//1为插入的参数1,2。。。fileInStream为插入的数据,bytes为字节长度
pstmt.executeUpdate();
conn.close();
fis.close();
}catch(Exception e){
System.out.println(e.getMessage());