2 回答

TA貢獻1827條經驗 獲得超8個贊
您正在嘗試使用 java 代碼中的用戶連接它sys,但表employee存在于hr架構中。
您可以更改:
//Change this line from
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:hr/hr@localhost:1521/orclpdb","sys as sysdba","Oracle_1");
// to
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:hr/hr@localhost:1521/orclpdb","hr","hr");
或者
您可以更改從表中獲取數據的方式employee(使用其架構查詢表)
//Change this line from
ResultSet rs=stmt.executeQuery("select count(*) from employees");
//to
ResultSet rs=stmt.executeQuery("select count(*) from hr.employees");
干杯??!

TA貢獻1794條經驗 獲得超8個贊
請嘗試一下這段代碼。它必須工作
public static void conn() throws ClassNotFoundException, SQLException{
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orclpdb", "HR", "HR");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select count(*) from dual");
while(rs.next())
System.out.println(rs.getInt(1));
con.close();
}
添加回答
舉報