Java EE 报错
Exception in thread "main" 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 'id=\'W5M0MpCehiHzreSzNTczkc9d\'?>
代码:
static void create() throws SQLException, IOException{
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
conn = JdbcUtils.getConnection();
String sql = "insert into toufa values(?)";
ps = conn.prepareStatement(sql);
File file = new File("ss.jpg");
InputStream in = new BufferedInputStream(new FileInputStream(file));
ps.setBinaryStream(1, in,(int)file.length());
int i = ps.executeUpdate();
in.close();
System.out.println("i="+i);
}finally{
JdbcUtils.free(rs, ps, conn);
}
}
大神们,怎么办啊!!!
Exception in thread "main" 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 'id=\'W5M0MpCehiHzreSzNTczkc9d\'?>
代码:
static void create() throws SQLException, IOException{
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
conn = JdbcUtils.getConnection();
String sql = "insert into toufa values(?)";
ps = conn.prepareStatement(sql);
File file = new File("ss.jpg");
InputStream in = new BufferedInputStream(new FileInputStream(file));
ps.setBinaryStream(1, in,(int)file.length());
int i = ps.executeUpdate();
in.close();
System.out.println("i="+i);
}finally{
JdbcUtils.free(rs, ps, conn);
}
}
大神们,怎么办啊!!!
当前问题共有如下(1)个解决方案
你的表段id是否是int型?如果是,后面为啥条件为字符串?id=\'W5M0M....
将语句手动修改测试一下就知道,比如id=123 .....测试一下,无错误就找到地方了
接着去修正那个部分内容,为什么id会是一个定符串
更多参考:Mysql错误码及释意大全
http://snowcoal.com/article/732.html