【发布时间】:2017-01-02 10:21:26
【问题描述】:
package database;
import java.sql.*;
public class MysqlCon {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/neha","root","root");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next());
System.out.println(rs.getInt(1)+" "+rs.getString(2));
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
【问题讨论】:
-
java.sql.SQLException: 结果集结束后
-
您在 while 之后立即有一个
;,因此您的代码不会像您认为的那样做。这也是为什么一致的缩进和总是使用块是可取的。投票结束是一个错字。