How do I login to 'xe' connection in Oracle 11g with java code?

风格不统一 提交于 2020-01-11 10:46:46

问题


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 and password = 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

回答1:


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




回答2:


Unfortunately, your answer is a bit too vague.

  • If you want to login to databases through Java, use JDBC.
  • If you're wanting to automate the logging in of an external program, you've got the wrong language :)
  • If you're wanting to verify the database is up, see the first point.

Overall, look to JDBC. Oracle's documentation of JDBC can be found here.




回答3:


You should write the following code :

private String driver="oracle.jdbc.driver.OracleDriver";
private String dbURL="jdbc:oracle:thin:@localhost:1521:XE";
private String dbUserName="sys as sysdba";
private String dbPassword="123456";


try{
Class.forName(driver);
con=DriverManager.getConnection(dbURL,dbUserName,dbPassword);
-----//Rest of your Code//-------
}catch(Exception e){
e.printStackTrace();
}


来源:https://stackoverflow.com/questions/11945255/how-do-i-login-to-xe-connection-in-oracle-11g-with-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!