public class TestJDBC { public static void main(String[] args){
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.5:1521:OracleDP", "scott", "tiger");
stmt=conn.createStatement();
rs=stmt.executeQuery("select*from dept");
while(rs.next()){
System.out.println(rs.getString("deptno"));
}
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
if(conn!=null){
conn.close();
conn=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}}
这个程序在运行在while(rs.next())这句话的时候出现了异常,在我的lomboz_eclipse上报的是java.sql.SQLException:ORA-01009:缺少法定参数.
也就是说在一开始执行while语句的时候就出现了错误。但是rs.next()方法的返回值是boolean类型,为什么还要报错误。我调试了很久始终没想痛为什么会报这样的异常,请各位高手些指点下,小弟感激不尽~~
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
//new oracle.jdbc.driver.OracleDriver();
conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.5:1521:OracleDP", "scott", "tiger");
stmt=conn.createStatement();
rs=stmt.executeQuery("select*from dept");
while(rs.next()){
System.out.println(rs.getString("deptno"));
}
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
if(conn!=null){
conn.close();
conn=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}}
这个程序在运行在while(rs.next())这句话的时候出现了异常,在我的lomboz_eclipse上报的是java.sql.SQLException:ORA-01009:缺少法定参数.
也就是说在一开始执行while语句的时候就出现了错误。但是rs.next()方法的返回值是boolean类型,为什么还要报错误。我调试了很久始终没想痛为什么会报这样的异常,请各位高手些指点下,小弟感激不尽~~
解决方案 »
- 大家帮看看,很简单的东西,继承覆盖,在线求
- super.init(config)问 题急急急
- SQL 出错,请大家告诉我哪错误
- JAVA程序编译后无法运行
- lucene+heritrix day3(1)
- Websphere、Weblogic,JBoss 那一种平台入门最快?
- JPanel 的布局设置是gridlayout 我想把一个JBUTTON按纽放到第3行第2列需要怎么写?
- Linux 下javac 编译的问题,高分求解.....
- 简单的javaBean问题
- 为何这段代码,书中说可能会打印0,但在我在eclipse执行完后ready一直被主线程赋值了true,进不了while循环
- 一个静态变量的怪问题(内附例子)
- 如何将电脑中的所有文件都添加到Jtree中
楼主【duandpeng301】截止到2008-08-01 13:02:17的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0 每贴平均分数:0
回帖的总数量:3 得分贴总数量:1 回帖的得分率:33%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=duandpeng301
注意空格