您现在的位置: 软界网软界问答软件开发Java > 问题显示
我要提问    
提示:提问和回答别人的问题均可赢得积分
加入收藏我要投诉 我来回答
此问题已经被浏览82次,收藏:0次. 所属类别:[Java]
问题:no current row in the result?
问题就出现在这段代码中,各位看有什么不对的地方吗?

ctx = new InitialContext();
if (ctx == null)
throw new Exception( "ctx==null ");
ds = (DataSource) ctx.lookup( "java:comp/env/jdbc/connectDB ");
if (ds == null)
throw new Exception( "ds==null ");
conn = ds.getConnection();
if (conn == null)
throw new Exception( "conn==null ");
stmt = conn.createStatement();

strStuCode = request.getParameter( "stucode ");
strSql = "select * from stuinformationT where stucode= "+strStuCode;
rs = stmt.executeQuery(strSql);
rs.next();
strStuCode = rs.getString( "stucode ");
strStuName = rs.getString( "stuname ");
strStuAge = rs.getString( "stuage ");
提问时间:2007-7-17 10:33:11 回答次数:(2) 提问人:软界网友 我来回答
回答(1)
rs = stmt.executeQuery(strSql);
rs.next();
strStuCode = rs.getString( "stucode ");
strStuName = rs.getString( "stuname ");
strStuAge = rs.getString( "stuage ");
问题出在 rs.next();
没有判断rs.next()是否有记录的情况
根据你出的错误,则表示当前查询没有查出记录。正确的做法
if(rs.next())
{
strStuCode = rs.getString( "stucode ");
strStuName = rs.getString( "stuname ");
strStuAge = rs.getString( "stuage ");

}else
{
//处理没有记录的情况
}
回答人:软界网友 我来回答
回答(2)
我作了异常的捕获

回答人:软界网友 我来回答
相关问题
关键字: getString,null,strStuCode,conn,next,ctx,if,ds,thrownewException,strStuName,strStuAge,strSql,stmt,没有,executeQuery,onnect
我来回答
验证码