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());
}
}
}
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!


