Exception in thread "main" java.sql.SQLException: 用尽的 Resultset
来源:百度知道 编辑:UC知道 时间:2024/06/02 01:30:47
那里错了哦
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"));
}
}
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"));
}
}
while(rs.next());不要用分号
System.out.println(rs.getString("deptno"));这一句是while的内容,建议使用{}括起来.
像你这样子已经打印指定的行内容,就无需用WHILE语句了,边NEXT()都不用.
正确写法:
while(rs.next())
{
System.out.println(rs.getString("deptno"));
}
还有,连接数据库,最好用个单独的方法是完成.
你的主运行方法里虽然抛出了异常,但是边接数据库的某些异常JAVA虚拟机是处理不了的,必须要你自己去捕获并进行处理.
看你的代码写得不够成熟,加油.
while(rs.next());
这行是不是写错了?遍历RESULTSET又不干什么事,最后还是打印RS的内容
就是一楼说的,你看看while后面一个分号,证明没干什么事,然后你又输出rs,while里边已经是最后一个rs了,你还输出,能不错么,越界了;如果后边没有分号,证明是运行后边一句,就不会又错了。好,问题解决了,现在你的问题就是把分给我,还是》》》》
你在最后关闭rs应该不会出这个异常了
rs.close();
Exception EOleSysError in module
英语作文,主题:in th park
Realistic novel in the 18th century
on June 5th和in June
Christmas in the 13th Month
nothing in thé world 是什么意思?
Report ranks China 6th in overall strength 怎么翻译?
谁能告诉我feminism in 17th century 在英国
The film was released on 11th July in China
Fashions in America before the 19th century_____those of Egland.