您的位置:程序门 -> java -> web 开发



急  下面的连接oracle的程序错在那里


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


急 下面的连接oracle的程序错在那里
发表于:2007-10-16 14:29:07 楼主
public   class   test   {
connection   con   =   null;

statement   stmt   =   null;

resultset   rs   =   null;

string   url   =   "jdbc:oracle:thin:@192.168.0.89:1521:orcl";

string   uid   =   "test1";

string   pwd   =   "test1";

public   void   a()   {
try   {
class.forname("oracle.jdbc.driver.oracledriver");
con   =   drivermanager.getconnection(url,   uid,   pwd);
stmt   =   con.createstatement();
rs   =   stmt.EXECutequery("select   *   from   tic_user");

while(rs!=null){
system.out.println(rs.getstring(0));
}
}   catch   (classnotfoundexception   e)   {
//   todo   auto-generated   catch   block
e.printstacktrace();
}   catch   (sqlexception   e)   {
//   todo   auto-generated   catch   block
e.printstacktrace();
}
}

public   static   void   main(string[]   args)   {
test   tt   =   new   test();
tt.a();
}
}
发表于:2007-10-16 14:43:131楼 得分:0
把上边代码
while(rs!=null){  
    system.out.println(rs.getstring(0));  
}  

改为:

while(rs.next()){  
      system.out.println(rs.getstring(0));  
}  
发表于:2007-10-16 16:06:022楼 得分:0
1、while(rs.next())
2、另外加上
finally{
rs.close();
stmt.close();
conn.close();
}
发表于:2007-10-16 17:57:123楼 得分:0
同意楼上!
如果还是错的,就看你有没有添加oracle驱动包,还有就是你的tomcat的端口号是否正确了!


快速检索

最新资讯
热门点击