大哥大姐们,我用jsp往数据库存二进制的图片,老是提示错误啊。我分两步,1.file成实例 2.改为二进制
错误如下:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:YouhaveanerrorinyourSQ...
错误如下:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 ''book'
values('1',_binary'??\0JFIF\0\0`\0`\0\0?\0Adobe\0d\0\0\0\0?]Exif\0' at
line 1
代码如下:
File file1=new File(“这是一个具体地址来着。。。。。”);
FileInputStream photoStream=new FileInputStream(file1);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection coon = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbhouse","root","root");
PreparedStatement pstmt = null;
String sql = "insert into 'book' values(?,?)";
pstmt = coon.prepareStatement(sql);
pstmt.setString(1,newBookName);
pstmt.setBinaryStream(2,photoStream,(long)photoStream.available());
pstmt.executeUpdate();
pstmt.close();
coon.close();
大哥大姐 帮帮忙啊,我鼓捣了好几天,实在不行啊。谢谢你们了。。 展开
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 ''book'
values('1',_binary'??\0JFIF\0\0`\0`\0\0?\0Adobe\0d\0\0\0\0?]Exif\0' at
line 1
代码如下:
File file1=new File(“这是一个具体地址来着。。。。。”);
FileInputStream photoStream=new FileInputStream(file1);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection coon = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbhouse","root","root");
PreparedStatement pstmt = null;
String sql = "insert into 'book' values(?,?)";
pstmt = coon.prepareStatement(sql);
pstmt.setString(1,newBookName);
pstmt.setBinaryStream(2,photoStream,(long)photoStream.available());
pstmt.executeUpdate();
pstmt.close();
coon.close();
大哥大姐 帮帮忙啊,我鼓捣了好几天,实在不行啊。谢谢你们了。。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询