strDBError="";
try{
countInt = drpStmt.executeUpdate(updateString);
}catch(SQLException sqlz){
countInt=-1;//返回-1,表示发生错误
strDBError="Error occur while using dataConn.exeUpdate()!The SQL is:<p>" + updateString + "<p>来自数据库的出错信息为:<P>" + sqlz.getMessage();
}
return countInt;
}
//--------------------------------------------------------------------
//-------------------------------------------------------
//获取指定SQL查询语句执行后返回的记录数
//避免在strSQL中包含“order by”语句,如果有则除去,否则会出错。
//去掉“order by”子句对于获取总记录数没有任何影响。
public int getRowCount(String queryString){
countInt=0;
strDBError="";
ResultSet rs;
int nRowCount=0;
try{
rs=drpStmt.executeQuery("select count(*) from (" + queryString + ") as viewTempQueryString" );
while(rs.next()) nRowCount=rs.getInt(1);
}
catch(SQLException errGetRowCount){
countInt=-1;//发生错误
strDBError+="Error occur while useing dataConn.getRowCount("+queryString+")! 请与管理员联系。<p>从数据库返回的错误信息为:" + errGetRowCount.getMessage();
}catch(java.lang.Exception errOther){
countInt=-2;
strDBError+="<p>其他错误:" + errOther.getMessage();
}
return nRowCount;
}
//-----------------------------------------------------------
}//end of all
Test.jsp源代码-----------------
<jsp:useBean id="conDB" scope="session" class="DB.dataConn" />
<%
String strSQL="select * from table";
ResultSet rs=conDB.exeQuery(strSQL);
if(conDB.getErrorCode()<0){
out.println("发生错误:"+conDB.getErrorInfo());
out.close();
}
%>






