MySQL 插入二进制数据的问题

hdj_myth 2011-11-08 04:41:11

import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class test {
public static void main(String[] args) {
create();
}

static void create(){
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
conn = JDBCUtils.getConnection();
String sql = "insert into blob(data) values(?)";
ps = conn.prepareStatement(sql);
File file = new File("02.jpg");
InputStream in = new BufferedInputStream(new FileInputStream(file));
ps.setBinaryStream(1, in, file.length());

int i = ps.executeUpdate();
in.close();
System.out.println(i);
}catch(Exception e){
e.printStackTrace();
}finally{
JDBCUtils.free(rs, ps, conn);
}
}
}


报错信息:
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 'blob(data) values(_binary'??\0JFIF\0\0`\0`\0\0?\0C\0
' at line 1
Mysql和Eclipse的字符集都是“GBK”
问量出在哪里呢?
...全文
118 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hdj_myth 2011-11-08
  • 打赏
  • 举报
回复
补充:插入字符类型的数据没有问题

67,516

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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