last public boolean last() throws SQLExceptionMoves the cursor to the last row in this ResultSet object. Returns: true if the cursor is on a valid row; false if there are no rows in the result set Throws: SQLException - if a database access error occurs or the result set type is TYPE_FORWARD_ONLY Since: 1.2 //the result set type is TYPE_FORWARD_ONLY时会抛出异常。所以应该把result set类型给改成直接访问最后一个row的。
我查了我的prepareStatement,发现有2种。 public void prepareStatement(String sql) throws GenericDataSourceException, GenericEntityException { this.prepareStatement(sql, false, 0, 0); } public void prepareStatement(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency) throws GenericDataSourceException, GenericEntityException { if (Debug.verboseOn()) Debug.logVerbose("[SQLProcessor.prepareStatement] sql=" + sql, module); if (_connection == null) { getConnection(); } try { _sql = sql; _ind = 1; //add by gary at 2003-12-01 synchronized(this) { if (specifyTypeAndConcur) { _ps = _connection.prepareStatement(sql, resultSetType, resultSetConcurrency); } else { _ps = _connection.prepareStatement(sql); } } } catch (SQLException sqle) { throw new GenericDataSourceException("SQL Exception while executing the following:" + sql, sqle); } } 能告诉我第2种怎么用么?boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency不太明白
prepareStatement(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency) 试一试 prepareStatement(String sql, true, 1, 1) 没有用过,不过你把各种组合都试一试,应该可以
String helper = delegator.getEntityHelperName("Product");
SQLProcessor sqlP = new SQLProcessor(helper);
StringBuffer query = new StringBuffer();
ResultSet rs = null;
try{
sqlP.prepareStatement(sqlString);
rs = sqlP.executeQuery();
}catch{.....}
performSearchCsc(...)
{
......
ResultSet rs = null;
try
{
rs = InventoryDao.searchCscAll(delegator, fields);
WriteData(rs);
}
......
}
public static ResultSet searchCscAll(...)
{
写sql语句;
rs = sqlP.executeQuery();//得到查询结果,有数据。
return rs;
}
private void WriteData(ResultSet rs)
{
....
while (rs.next()){}
.... {
}
目前,在searchCscAll()里面用rs.next()是没有问题的。
在performSearchCsc()里用rs.next()也是没有问题的。
但是在private void WriteData(ResultSet rs)里用rs.next()就抱错
“COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver] CLI0125E 函数顺序错误。 SQLSTATE=HY010”
public boolean last()
throws SQLExceptionMoves the cursor to the last row in this ResultSet object. Returns:
true if the cursor is on a valid row; false if there are no rows in the result set
Throws:
SQLException - if a database access error occurs or the result set type is TYPE_FORWARD_ONLY
Since:
1.2
//the result set type is TYPE_FORWARD_ONLY时会抛出异常。所以应该把result set类型给改成直接访问最后一个row的。
public void prepareStatement(String sql) throws GenericDataSourceException, GenericEntityException {
this.prepareStatement(sql, false, 0, 0);
} public void prepareStatement(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency) throws GenericDataSourceException, GenericEntityException {
if (Debug.verboseOn()) Debug.logVerbose("[SQLProcessor.prepareStatement] sql=" + sql, module); if (_connection == null) {
getConnection();
} try {
_sql = sql;
_ind = 1;
//add by gary at 2003-12-01
synchronized(this)
{
if (specifyTypeAndConcur) {
_ps = _connection.prepareStatement(sql, resultSetType, resultSetConcurrency);
} else {
_ps = _connection.prepareStatement(sql);
}
}
} catch (SQLException sqle) {
throw new GenericDataSourceException("SQL Exception while executing the following:" + sql, sqle);
}
}
能告诉我第2种怎么用么?boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency不太明白
试一试
prepareStatement(String sql, true, 1, 1)
没有用过,不过你把各种组合都试一试,应该可以