eclipse mysql5.0保存图片时出现异常

dddgggfffhhhyyy 2011-04-22 11:04:03
源码:
import java.sql.Connection ;
import java.sql.DriverManager ;
import java.sql.SQLException ;
import java.sql.PreparedStatement ;
import java.io.File ;
import java.io.FileInputStream;
import java.io.FileOutputStream ;
import java.sql.ResultSet ;
import java.io.InputStream ;
import java.io.OutputStream ;
public class BlobDemo02{
// 定义MySQL的数据库驱动程序
public static final String DBDRIVER = "org.gjt.mm.mysql.Driver" ;
// 定义MySQL数据库的连接地址
public static final String DBURL = "jdbc:mysql://localhost:3306/user" ;
// MySQL数据库的连接用户名
public static final String DBUSER = "root" ;
// MySQL数据库的连接密码
public static final String DBPASS = "xiaogui" ;
public static void main(String args[]) throws Exception{ // 所有异常抛出
FileInputStream fis = null;
Class.forName(DBDRIVER);
Connection con = null;
con = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
File file = new File("f:" + File.separator + "copy.jpg");
fis = new FileInputStream(file);
PreparedStatement pstmt = null;
String name = "jin";
String sql = "insert into userblob(name,photo) values (?,?)";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, name);
System.out.println("ok");
pstmt.setBinaryStream(2, fis,fis.available());
pstmt.executeUpdate();
pstmt.close();
con.close();
fis.close();
}
};
异常:
ok
Exception in thread "main" com.mysql.jdbc.exceptions.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 '\0;èk8^7??|?ì{??a?
????Z:ù?_????w#x|èt??à-?`G×l}???ò0í?N?p??8h????‘??=??·?' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at BlobDemo02.main(BlobDemo02.java:34)
...全文
41 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧