mysql PreparedStatement executeBatch SQL语句的问题
2012-03-26 15:55
609 查看
今天在使用executeBatch时,使用一个很简单的表
做批量插入
CREATE TABLE IF NOT EXISTS `fnbl_dummy` ( `id` varchar(32) NOT NULL, `userid` bigint(20) NOT NULL, `last_update` bigint(20) NOT NULL, `status` char(1) NOT NULL, `p_content` varchar(200) NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
做批量插入
String SQL_INSERT_INTO_FNBL_DUMMY = "INSERT INTO fnbl_dummy(id,userid,last_update,status,p_content) VALUES (?,?,?,?,?);"; Connection con = null; PreparedStatement ps = null; try { con = getUserDataSource().getRoutedConnection(userId); con.setAutoCommit(false); ps = con.prepareStatement(SQL_INSERT_INTO_FNBL_DUMMY); for (DummyWrapper item : items) { Timestamp lastUpdate = item.getLastUpdate(); if (lastUpdate == null) { lastUpdate = new Timestamp(System.currentTimeMillis()); } ps.setString(1, item.getId()); ps.setLong(2, Long.parseLong(this.userId)); ps.setLong(3, lastUpdate.getTime()); ps.setString(4, String.valueOf(Def.PIM_STATE_NEW)); ps.setString(5, StringUtils.left(item.getContent(), SQL_LASTNAME_DIM)); ps.addBatch(); } int []len = ps.executeBatch(); con.commit(); return len.length; } catch (Exception e) { log.error(e.toString()); throw new DAOException("Error adding dummy items.", e); } finally { DBTools.close(con, ps, null); }结果运行是单条测试一直OK,多条测试一直提示“java.sql.BatchUpdateException: 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 ”,查找原因竟然是因为SQL语句最后的";"分号问题,无语
相关文章推荐
- PreparedStatement executeBatch()的返回值的问题
- Windows sql语句正则匹配导出数据到本地 The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
- PreparedStatement.executeBatch返回值问题
- PreparedStatement executeBatch()的返回值的问题(转)
- 用SQL语句解决mysql导入大数据文件的问题
- org.hibernate.exception.SQLGrammarException:Could not execute JDBC batch update问题的解决
- sql语句之表间字段值复制遇到的一些问题--基于mysql
- 关于mysql里面写sql语句,或者直接在表里写汉字,都是乱码问题解决
- jdbc 链接mysql执行sql语句出现中文乱码问题
- [MySQL] SQL语句中文别名乱码问题
- MySQL中的一些特性和SQL语句中需要注意的问题
- jdbc-mysql基础 PreparedStatement addBatch 批处理
- mysql导入导出数据中文乱码解决方法小结(1、navicat导入问题已解决,创建连接后修改连接属性,选择高级->将使用Mysql字符集复选框去掉,下拉框选择GBK->导入sql文件OK;2、phpmyadmin显示乱码的问题也解决,两步:1.将sql文件以utf8的字符集编码另存,2.将文件中sql语句中的字段字符集编码改成utf8,导入OK)
- mysql之sql语句细节问题汇总
- linux环境mysql的sql语句严格区分大小写问题
- mysql limit后的变量问题,sql语句的prepare
- mysql执行preparedStatement.executeUpdate时,只返回changedRows的行数,不返回涉及到的行数的办法
- mySql中的sql语句问题
- 在Eclipse中测试MySQL-JDBC(9)statement 批处理(同时执行多条sql语句)
- Mysql SQL语句过长引起的问题