主题:查询数据库提示无效的游标状态
数据库连接没有问题,字段的顺序也没有错误,可是总是提示无效的游标状态
Connection conn=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=E:/chenzhou/workspace/myweb/mydb.mdb";
conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from employee");
out.println("<table>");
out.println("<tr>");
out.println("<td>编号</td>");
out.println("<td>姓名</td>");
out.println("<td>性别</td>");
out.println("<td>工资</td>");
out.println("</tr>");
while(rs.next());
{
out.println("<tr>");
out.println("<td>"+rs.getString("no")+"</td>");
out.println("<td>"+rs.getString("name")+"</td>");
out.println("<td>"+rs.getString("sex")+"</td>");
out.println("<td>"+rs.getFloat("salary")+"</td>");
out.println("</tr>");
}
out.println("</table>");
rs.close();
stmt.close();
}
catch(ClassNotFoundException e)
{
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println(e.getMessage());
}
finally
{
try
{
if(conn!=null)
conn.close();
}
catch(Exception e)
{
}
}
Connection conn=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=E:/chenzhou/workspace/myweb/mydb.mdb";
conn=DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from employee");
out.println("<table>");
out.println("<tr>");
out.println("<td>编号</td>");
out.println("<td>姓名</td>");
out.println("<td>性别</td>");
out.println("<td>工资</td>");
out.println("</tr>");
while(rs.next());
{
out.println("<tr>");
out.println("<td>"+rs.getString("no")+"</td>");
out.println("<td>"+rs.getString("name")+"</td>");
out.println("<td>"+rs.getString("sex")+"</td>");
out.println("<td>"+rs.getFloat("salary")+"</td>");
out.println("</tr>");
}
out.println("</table>");
rs.close();
stmt.close();
}
catch(ClassNotFoundException e)
{
out.println(e.getMessage());
}
catch(SQLException e)
{
out.println(e.getMessage());
}
finally
{
try
{
if(conn!=null)
conn.close();
}
catch(Exception e)
{
}
}