How do I login to 'xe' connection in Oracle 11g with java code?
13,983
If you want to connect as SYS you have to use sys as sysdba
So in your java code try like the following code
String url = "jdbc:oracle:thin:@//localhost:1521:xe";
String username = "sys as sysdba";
String password = "123456";
Connection connection= DriverManager.getConnection(url, username, password);
Regards
Author by
sweet dreams
Life can be very beautiful, only if we choose to make it so.
Updated on July 23, 2022Comments
-
sweet dreams almost 2 years
I want to make java code that does only this:
Login to the 'xe' connection in Oracle 11g database. That's all. How can do it ?
EDIT: yes, i was using JDBC, but unable to login to that connection. My url is
jdbc:oracle:thin:@//localhost:1521/xe
,username = sys
andpassword = 123456
for the xe or sys connection. Then why can't i login to that connection ?EDIT:
I am very sorry, I forgot to add that I see another error besides the 1st one, i.e.
SQLException: ORA-28009: connection as SYS should be as SYSDBA or SYSOPER
This is followed by-
Exception in thread "main" java.lang.NullPointerException
-
sweet dreams over 11 yearsFor- 1- yes, please refer to the edit in question. 2- why is it wrong ? 3- no. want to create the database/schema/user/other user or whichever uncommon name oracle decided to give it :(
-
sweet dreams over 11 yearsWorks !I thought that since the username for connection 'xe' is sys and password is 123456, setting my username = sys only in java code would work. Btw, why does "sys as sysdba" work and not just "sys" ?
-
Jacob over 11 yearsBecause sys is a privileged user and hence we need to use
sys as sysdba
. From docTo connect to Oracle Database as a privileged user over a nonsecure connection, you must be authenticated by a password file. When using password file authentication, the database uses a password file to keep track of database user names that have been granted the SYSDBA or SYSOPER system privilege. This form of authentication is discussed in "Using Password File Authentication".
-
Nenad Bulatović over 9 yearsShouldn't be there ; after String password = "123456" ?
-
Jacob over 9 years@NenadBulatovic Unquestionably yes, it was a typo and corrected. Thanks