Exception in thread "main" java.sql.SQLException:用尽的 Resultset那里错了哦import java.sql.*;public class jdbc{public static void main(String[] args) throws ClassNotFoundException,SQLException{Class.forName("oracle.jdbc.driver.OracleDriver");
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/05 12:56:41
![Exception in thread](/uploads/image/z/14029999-7-9.jpg?t=Exception+in+thread+%22main%22+java.sql.SQLException%3A%E7%94%A8%E5%B0%BD%E7%9A%84+Resultset%E9%82%A3%E9%87%8C%E9%94%99%E4%BA%86%E5%93%A6import+java.sql.%2A%3Bpublic+class+jdbc%7Bpublic+static+void+main%28String%5B%5D+args%29+throws+ClassNotFoundException%2CSQLException%7BClass.forName%28%22oracle.jdbc.driver.OracleDriver%22%29%3B)
Exception in thread "main" java.sql.SQLException:用尽的 Resultset那里错了哦import java.sql.*;public class jdbc{public static void main(String[] args) throws ClassNotFoundException,SQLException{Class.forName("oracle.jdbc.driver.OracleDriver");
Exception in thread "main" java.sql.SQLException:用尽的 Resultset
那里错了哦
import java.sql.*;
public class jdbc
{
public static void main(String[] args) throws ClassNotFoundException,SQLException
{
Class.forName("oracle.jdbc.driver.OracleDriver");
// new oracle.jdbc.driver.OracleDriver();
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@198.162.0.1:1521:ORCL","scott","tiger");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from emp");
while(rs.next());
System.out.println(rs.getString("deptno"));
}
}
Exception in thread "main" java.sql.SQLException:用尽的 Resultset那里错了哦import java.sql.*;public class jdbc{public static void main(String[] args) throws ClassNotFoundException,SQLException{Class.forName("oracle.jdbc.driver.OracleDriver");
while(rs.next());不要用分号
System.out.println(rs.getString("deptno"));这一句是while的内容,建议使用{}括起来.
像你这样子已经打印指定的行内容,就无需用WHILE语句了,边NEXT()都不用.
正确写法:
while(rs.next())
{
System.out.println(rs.getString("deptno"));
}
还有,连接数据库,最好用个单独的方法是完成.
你的主运行方法里虽然抛出了异常,但是边接数据库的某些异常JAVA虚拟机是处理不了的,必须要你自己去捕获并进行处理.
看你的代码写得不够成熟,加油.