错误笔记:写项目时用PreparedStatement向数据库中插入数据报游标不足错误
来源:互联网 发布:list转换成byte数组 编辑:程序博客网 时间:2024/05/18 02:47
今天在写一个电信宽带运营支撑系统时,报了一个游标不足的错误,一脸蒙,代码是这样:
public void saveToDB(Collection<BIDR> arg0) throws Exception {Connection conn = ConnectionFaction.getConnection();//conn.setAutoCommit(false);//int num=0;for(BIDR b:arg0) {//num++;int i = new Date(b.getLogin_date().getTime()).getDate();System.out.println(i);String sql="insert into t_detail_"+i+" values(?,?,?,?,?,?)";PreparedStatement prs = conn.prepareStatement(sql);prs.setString(1, b.getAAA_login_name());prs.setString(2, b.getLogin_ip());prs.setTimestamp(3, b.getLogin_date());prs.setTimestamp(4, b.getLogout_date());prs.setString(5, b.getNAS_ip());prs.setInt(6, b.getTime_deration());prs.execute();}//conn.commit();}很简单的使用jdbc向数据库中插入数据的语句,为什么会报游标不足的错误呢?
想了好久,发现以前写preparedStatement时都是在循环外建的对象,这次是在for循环内,因为特殊需要,那么可能是preparedStatement对象没有关闭导致的吗?
于是在每次执行玩sql语句后,都关闭以下preparedStatement。
public void saveToDB(Collection<BIDR> arg0) throws Exception {Connection conn = ConnectionFaction.getConnection();//conn.setAutoCommit(false);//int num=0;for(BIDR b:arg0) {//num++;int i = new Date(b.getLogin_date().getTime()).getDate();System.out.println(i);String sql="insert into t_detail_"+i+" values(?,?,?,?,?,?)";PreparedStatement prs = conn.prepareStatement(sql);prs.setString(1, b.getAAA_login_name());prs.setString(2, b.getLogin_ip());prs.setTimestamp(3, b.getLogin_date());prs.setTimestamp(4, b.getLogout_date());prs.setString(5, b.getNAS_ip());prs.setInt(6, b.getTime_deration());prs.execute();prs.close();}插入成功!
记录一下~~~~
阅读全文
0 0
- 错误笔记:写项目时用PreparedStatement向数据库中插入数据报游标不足错误
- 错误笔记:JDBC向oracle数据库中插入数据遇到线程阻塞问题
- Java向数据库中插入数据出错时怎么避免插入错误数据
- 向sql数据库中插入空时间报系统错误的解决方法
- 向sql数据库中插入空时间报系统错误的解决方法
- strute+hibernate+spring错误求助,向数据库插入不了数据
- PreparedStatement批量向数据库插入数据报了这个异常:java.sql.SQLException:ORA-01722: 无效数字
- database returned no natively generated向mysql数据库插入数据时的错误
- 向数据库中插入数据:
- 持久层用PreparedStatement.setTimestamp()向数据库插入日期字段
- 向MySQL数据库中插入数据,sql语句没问题,但插入失败也不报错?
- 错误笔记:JDBC中Statement和PreparedStatement对于Date类型写入数据库问题
- informix插入数据报271,136错误
- 用 PreparedStatement 向 SqlServer 中一次性插入多条记录
- 关于java中向数据库中插入数据时,报错Caused by: java.lang.NullPointerException的问题
- SSH项目中向数据库写中文数据时出现乱码解决办法
- 向derby数据库中插入数据
- 向数据库中批量插入数据
- 类的一般形式
- 在linux环境下编译运行OpenCV程序的两种方法
- leetcode-Number of Islands
- 【Scikit-Learn 中文文档】特征选择
- 利用程序写caffe协议:同名层
- 错误笔记:写项目时用PreparedStatement向数据库中插入数据报游标不足错误
- C#:另一种判断质数的代码,并统计数量
- 被static修饰的成员变量可以被修改吗
- [基础题] 6.(*)按如下要求编写Java程序: (1)编写一个接口:OneToN,只含有一个方法int dispose(int n)
- 习题6.11
- numpy.logspace用法
- unity中特殊的文件夹
- 【JS】发布/订阅模式
- python基础-PyYaml操作yaml文件