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

前端 未结 3 1059
北荒
北荒 2021-01-21 17:02

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,

相关标签:
3条回答
  • 2021-01-21 17:17

    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();
    }
    
    0 讨论(0)
  • 2021-01-21 17:22

    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.

    0 讨论(0)
  • 2021-01-21 17:26

    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

    0 讨论(0)
提交回复
热议问题