您的位置:首页 > 编程语言 > Java开发

java setBinaryStream error for mysql

2012-12-06 08:42 260 查看
Class.forName(driver);

Connection conn=DriverManager.getConnection(url, user, password);

String sql="insert into [test] ([name],[img])values(?,?)";

InputStream is=new FileInputStream(new File("src/lsnu/lgf/saveimage/haha.jpg"));

System.out.println("len="+is.available());

PreparedStatement ps=conn.prepareStatement(sql);

ps.setString(1, "name");

ps.setBinaryStream(2, is,is.available());

System.out.print(ps.execute());

presentation:Exception in thread "main" java.sql.SQLException: 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 '[test] ([name],[img])values('ggggg',_binary'ertwertwederywgadfhsdfhgf

change:

String sql="insert into test (name,img)values(?,?)";

is ok;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐