日期:2014-05-18  浏览次数:20767 次

ps.executeBatch返回null?
spring+hibernate框架下,使用HibernateCallBack执行sql语句(非hql)

String modSql = "insert into m_modinfo (streamnumber, "
+ "committime, tablename,phoneNumber, sqlset, app) values(?," + "to_date('" + dateString
+ "','yyyy-MM-dd HH24:mi:ss'),?,?,?,?)";

DataSource ds = SessionFactoryUtils.getDataSource(session.getSessionFactory());
Connection conn = ds.getConnection();
ps = conn.prepareStatement(modSql);

for(Iterator<String> it = sqlsetList.iterator(); it.hasNext(); ){
String sqlset = it.next();

ps.setInt(1, streamNumber);
ps.setString(2, "plus_ringboxdepot");
ps.setString(3, provinceId);
ps.setString(4, sqlset);
ps.setString(5, "mng");

ps.addBatch();
}

int[] results = ps.executeBatch();


日志跟踪到的 results 是null。api对此没有解释,大神帮看看
下面是api对返回值的描述:
Returns:
an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch.
------解决方案--------------------
直接用SQLQuery就完了呗  你这么写  怎么维护
------解决方案--------------------
是不是数据连接问题,你写个简单的检索看看数据。
------解决方案--------------------
引用:
Quote: 引用:

直接用SQLQuery就完了呗  你这么写  怎么维护



Query query= session.createSQLQuery(sql); 
query.setString(0, sqlset);
int i = query.executeUpdate();

返回i为0,还是未执行


debug进去吧   否则异常了也不知道  也有可能是事务的原因