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();
}
添加回答
举报