解决 java.sql.SQLException: Before start of result set
java中使用如下代码做数据库连接,用以查询数据
*******************我是分割线*************************************
try {
Class.forName("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://127.0.0.1:3306/base_company";
conn = DriverManager.getConnection(connectionUrl,"root","root");
stmt = conn.createStatement();
String sqlString="SELECT count(1) as trueorfalse from base_user where usercode='"+name+"' and password='"+pwd+"';";
System.out.println(sqlString);
rs=stmt.executeQuery(sqlString);
while(rs.next())
{
result=rs.getString("trueorfalse");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*******************我是分割线*********************************************
缺少红色文字部分就会出现 java.sql.SQLException: Before start of result set异常,原因貌似是因为到了最后一条记录
----------------
Lynx
The quieter you become,the more you are able to hear.