JDBC java与oracle数据库连接问题
import java.sql.*;
public class TestJDBC {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName( "oracle.jdbc.driver.OracleDriver ");
Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:sys ", "sys ", "root ");
} catch(
SQLException e) {
e.printStackTrace();
} catch (
ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
出错信息:
java.sql.SQLException: ORA-28009: connection to sys should be as sysdba or sysoper
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:644)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:298)
at oracle.jdbc.driver.PhysicalConnection. <init> (PhysicalConnection.java:343)
at oracle.jdbc.driver.T4CConnection. <init> (T4CConnection.java:147)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:31)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:545)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at TestJDBC.main(TestJDBC.java:12)
------解决方案--------------------告诉你不是数据库的DBA或者操作员,请检查你的用户名和密码!
------解决方案--------------------如果在这里不能得到满意回答,请尝试到IT付费问答社区www.nlld.net提问
------解决方案--------------------connection to sys should be as sysdba or sysoper
连接到SYS用户必须是 sysdba or sysoper
------解决方案--------------------把 Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:sys ", "sys ", "root ");
改成:
Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:sys ", "sys ", "manager ");
------解决方案--------------------以sys用户这个方法是不能连接到的,因为sys连接的时候必须是sysdba or sysoper,而这个方式是normal的
所以你可以用system用户,或者别的用户scott(必须先激活)等连接就可以了。
------解决方案--------------------DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:sys ", "sys/root as dba ", " ");
试试看
------解决方案--------------------新建一个role.
CREATE ROLE TEST IDENTIFIED BY TEST ;
GRANT ALL PRIVILEGES ON TEST
DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521: "TEST ", "TEST ");
肯定就可以,normal方式连接;
------解决方案--------------------用sys登录不好用,最好作其它的用户身份,这也是比较安全的常用的,这个问题我在Hibernate中遇到过后来换了一个用户就可以了。