oracle数据库的名称为:mydata,用户名:system,密码:abcde,我想与数据库建立连接并输出表client中的前两列,请大家指教错在那里?
import java.sql.*;
public class Oracle{
public static void main(String[] args){
Connection conn = DriverManager.getConnection ("jdbc:odbc:mydata", "system", "abcde");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM client");
while(rs.next()){
System.out.println("您的第一个字段内容为:"+rs.getString(1));
System.out.println("您的第二个字段内容为:"+rs.getString(2));
}
System.out.println("数据库操作成功,恭喜你");
rs.close();
stmt.close();
conn.close(); }
}
import java.sql.*;
public class Oracle{
public static void main(String[] args){
Connection conn = DriverManager.getConnection ("jdbc:odbc:mydata", "system", "abcde");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM client");
while(rs.next()){
System.out.println("您的第一个字段内容为:"+rs.getString(1));
System.out.println("您的第二个字段内容为:"+rs.getString(2));
}
System.out.println("数据库操作成功,恭喜你");
rs.close();
stmt.close();
conn.close(); }
}
加多
try...就可以了.
另外,这是十分简单的JAVA程序了,楼主需要多多看书啊。
有JAVA的问题,多到JAVA版问吧,那里的人对JAVA了解得比较多。
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException
Unhandled exception type SQLException at Oracle.main(Oracle.java:4)
........}
catch(SQLException sqle)
System.out.print(sqle);
}