我收到此错误:
java.sql.SQLException: ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
怎么修?(我需要SYS
)。谢谢。
试试这个 :
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)
已经有了答案,
您正在尝试连接,sys
但服务器允许
任何一个
sys as sysdba
或者
sys as sysoper
只需将用户参数更改为上面的任何一个
user='sys as sysdba'
或者
user='sys as sysoper'
此代码有效
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);
如果您尝试像这样连接到数据库:connect SYS/<password>
您使用的语法不再有效(Oracle 9i 之后)。
而是尝试如下连接:
connect SYS/<password> as SYSDBA or connect SYS/<password> as SYSOPER
您可以使用 OracleDataSource 对象吗?
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;
}
}
并这样称呼它:
Connection con = null;
con = Database.openConnection("YourJDBCConnectionURL", "YourSYSUser", "YourSYSPassword", "sysdba");
如果要将数据库与“sys”以外的用户连接为“sysdba”,则必须将驱动程序从“thin”更改为“oci”才能成功连接。
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();
}
您需要将 sysdba 与用户字符串参数一起放入,例如
String user="sys as sysdba"
当我遇到同样的异常时,我的两分钱。以下为我做了诀窍:
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();
}