日期:2014-05-18  浏览次数:20682 次

急 下面的连接oracle的程序错在那里
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();
}
}

------解决方案--------------------
把上边代码
while(rs!=null){ 
System.out.println(rs.getString(0)); 


改为:

while(rs.next()){ 
System.out.println(rs.getString(0)); 


------解决方案--------------------
1、while(rs.next())
2、另外加上
finally{
rs.close();
stmt.close();
conn.close();
}
------解决方案--------------------
同意楼上!
如果还是错的,就看你有没有添加ORACLE驱动包,还有就是你的TOMCAT的端口号是否正确了!