Search code examples
javaoracle-databaseapachetomcatnetbeans-7

Oracle Database connectivity with java


Connectivity code

username="system";
 password="oracle11";
 url="jdbc:oracle:thin:@localhost:1523:system";
 Driver="oracle.jdbc.driver.OracleDriver";
 Class.forName(this.Driver);
 this.con=DriverManager.getConnection(this.url,this.username,this.password);
 System.out.println("Connect");

In the url "system" is globally connect to the oracle it access all the tables so no database security or sepration is there so how to differentiate it.I want to create diffrent database for diffrent projects how to make it in oracle and how to access with java


Solution

  • Try this:

    Open CMD:
    1. sqlplus / as sysdba;
    2. create user test identified by 123;
    3. grant all privileges to test;

    Here: test is the new user whose password is 123
    Now when you need to login with this user
    Type in CMD: Sqlplus test/123

    Correction:
    In URL:
    url="jdbc:oracle:thin:@localhost:1523:system";
    the last parameter should be SID
    Usually the Service Id is XE
    url="jdbc:oracle:thin:@localhost:1523:XE";