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/08/30 06:53:49
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虚拟机是处理不了的,必须要你自己去捕获并进行处理.
看你的代码写得不够成熟,加油.