java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position   即当前游标为空

 

出错了,代码如下:DBtest.jsp

<body>数据库查询:
<%
 Connection con = null;
con = DriverManager.getConnection("proxool.Develop");
if(con!=null){
Statement st= con.createStatement();
ResultSet rst=st.executeQuery("select * from user_info");
out.println(rst.getString("name"));
}
else
out.println("fail");
}catch(Exception e)
{e.printStackTrace();

%>
</body>

 

需要在程序中加入:rst.next();移动到有数据的地方才能取数据。

修改后的代码如下:

ResultSet rst=st.executeQuery("select * from user_info");

rst.next();
out.println(rst.getString("name"));

 

 

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐