Question

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 SYS). Thanks.

Was it helpful?

Solution

try this :

import java.sql as jsql
import java.lang as lang
driver, url, user, passwd = (
"oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:@localhost:1234:xxx1",
"sys as sysdba",
"xxx1")
 lang.Class.forName(driver)
 c = jsql.DriverManager.getConnection(url,user,passwd)

OTHER TIPS

Answers already there,

you are trying to connect as sys but the Server allows

either

sys as sysdba

or

sys as sysoper

just change user parameter as either one from above

user='sys as sysdba'

or

user='sys as sysoper'

This code works

String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName).newInstance();
String nameForConnect = "sys as sysdba";
String pass = "password";
String url = "jdbc:oracle:thin:@192.168.0.1:1521:ORCL";
Connection conn = DriverManager.getConnection(url, nameForConnect, pass);

If you have attempted to connect to the database like this: connect SYS/<password> you have used a syntax that is no longer valid (After Oracle 9i).

Instead try to connect as the following:

connect SYS/<password> as SYSDBA or connect SYS/<password> as SYSOPER

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");

If you want to connect your database with user other than "sys" as "sysdba" then you have to change the driver from "thin" to "oci" to make the successful connection.

try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        String DB_URL="jdbc:oracle:oci:@localhost:1521:orcl";
        OracleDataSource ds1=new OracleDataSource();
        Properties prop1 = new Properties();
        prop1.setProperty("user","ravi");
        prop1.setProperty("password","******");
        prop1.setProperty("internal_logon","sysdba");
        ds1.setConnectionProperties(prop1);
        ds1.setURL(DB_URL);
        OracleConnection conn1 = (OracleConnection)ds1.getConnection();
        Statement stmt = conn1.createStatement();
        ResultSet rs = stmt.executeQuery("select * from dba_users");
        while (rs.next())
            System.out.println(rs.getString(1));
        conn1.close();
    } catch (Exception e) {
        System.out.println(e);
    }
        /*It works for me*/
        /*also oci and thin is important if you want to connect with database which is installed in your clien (Computer) add oci if you want to install to server add thin*/

        String dbURL2 = "jdbc:oracle:oci:@172.16.24.123:1521:XE";
        String username = "sys as sysdba";
        String password = "XX Change it to your system password";
        
        try {
        Connection connection = DriverManager.getConnection(dbURL2, username, password);
            System.out.println("Connected to Oracle data");
        
    } catch (SQLException e) {
            System.out.println("Opps ! error");
            e.printStackTrace();
        
    }

You need to put sysdba with user String parameter like

String user="sys as sysdba"

My two cents as I ran into the same exception. Following did the trick for me:

           try (Connection conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@myserverip:1521:XE", "sys as sysdba", "Hello123")) {   
           // this worked too - "jdbc:oracle:thin:@myserverip:1521:XE", "system"
              if (conn != null) {
                  System.out.println("Connected to the database!");
              } else {
                System.out.println("Failed to make connection!");
              }
 
            } catch (SQLException e) {
              System.err.format("SQL State: %s\n%s", e.getSQLState(), e.getMessage());
            } catch (Exception e) {
            e.printStackTrace();
           }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top