How to connect in java as SYS to Oracle?

后端 未结 8 1817
花落未央
花落未央 2020-12-08 07:15

I receive this error:

java.sql.SQLException: ORA-28009: connection as SYS should be as SYSDBA or SYSOPER

How to fix? (I need to be SY

8条回答
  •  不知归路
    2020-12-08 08:01

    Are you able to use an OracleDataSource Object?

    public class Database {    
        static OracleDataSource ods;    
        public static Connection openConnection(String URL, String user, String password,     String option) throws SQLException
        {
                Connection conn = null;
                Properties properties = new Properties();
                properties.put("user", user);
                properties.put("password", password);
    
                ods = new OracleDataSource();
                ods.setURL(URL);
    
                if(option != null)
                {
                    properties.put("internal_logon", option);
                }
    
                ods.setConnectionProperties(properties);
                conn = ods.getConnection();
    
                return conn;
        }
    }
    

    And call it like this:

    Connection con = null;    
    con = Database.openConnection("YourJDBCConnectionURL", "YourSYSUser", "YourSYSPassword", "sysdba");
    

提交回复
热议问题