JDBC以sysdba身份连接oracle9i?

1.使用sys,无法连接。
String u = "sys";
String p = "fducs";        
String url = "jdbc:oracle:thin:@localhost:1521:fdu";

try {
                        Class.forName( "oracle.jdbc.driver.OracleDriver");
                        System.out.println( "Driver loaded");
} catch (ClassNotFoundException e) {
                         // TODO Auto-generated catch block
                        e.printStackTrace();
}

try {
                        con = DriverManager.getConnection(url, u, p);
                        System.out.println( "Database connected");
} catch (SQLException e) {
                         // TODO Auto-generated catch block
                        e.printStackTrace();
}
抛出异常:
java.sql.SQLException: ORA-28009: connection to sys should be as sysdba or sysoper

2.使用system as sysdba无法连接
String url = "jdbc:oracle:thin:@localhost:1521:fdu";

try {
        Class.forName( "oracle.jdbc.driver.OracleDriver");
        System.out.println( "Driver loaded");
} catch (ClassNotFoundException e) {
         // TODO Auto-generated catch block
        e.printStackTrace();
}

Properties     prop     =     new     Properties();    
prop.put( "user", "system");    
prop.put( "password", "fducs");    
prop.put( "defaultRowPrefetch", "15");    
prop.put( "internal_logon",     "sysdba");
try {
           con= DriverManager.getConnection(url, prop);
           System.out.println( "Database connected");
} catch (SQLException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
}
抛出异常:
java.sql.SQLException: ORA-01017: invalid username/password; logon denied

由此可见JDBC Thin连接Oracle只能以normal方式.应该是考虑安全性,实际中并不需要以sysdba身份从客户端连接到oracle数据库,应该采用别的授权用户

你可能感兴趣的:(oracle,jdbc,职场,sysdba,休闲)