我正在尝试学习连接到oracle数据库
当我以这种方式登录 sqlplus 时:
sqlplus sys/Oracle_1@orcl as sysdba;
我运行这段代码:
connect hr/hr@orclpdb
select count(*) from employees;
我得到这个输出:
COUNT(*)
----------
107
但是当我尝试在 java 代码中访问该表时,出现此错误:
ORA-00942: table or view does not exist
这是我的java代码:
class OracleCon{
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:hr/hr@localhost:1521/orclpdb","sys as sysdba","Oracle_1");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select count(*) from employees");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
我应该怎么做才能解决这个问题?
斯蒂芬大帝
幕布斯7119047
相关分类