关于向mysql数据库中写入文件的问题,求大神指点啊!!!public static void write(File file) throws Excepti
关于向mysql数据库中写入文件的问题,求大神指点啊!!!
public static void write(File file) throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection co=DriverManager.getConnection("jdbc:mysql://localhost:3306/abs","root","");
String sql="insert into file (id,file) values (?,?)";
PreparedStatement pst=co.prepareStatement(sql);
pst.setInt(1, 1);
InputStream in=new FileInputStream(file);
pst.setBinaryStream(2, in, in.available());
pst.executeUpdate();
System.out.println("写入Ok!");
in.close();
pst.close();
co.close();
}
public static void main(String[] args) throws Exception{
File file=new File("E://a.jpg");
write(file);
}运行提示sql语句错误???
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?kK?????—!?Vé??è???é????????b???}???????k??±?a6????#é????Yé??'?è??Cé???' at line 1
[解决办法]
SQL语句错误,你先把sql语句打印出来,然后再找错。
[解决办法]
看看你mysql支持不支持图片流的操作,
[解决办法]
数据库那段应该是2进制格式
[解决办法]
数据库中字段的类型
