Connecting to Oracle Database using JDBC

Connection connection = null;
try {
 // Instantiate  the appropirateJDBC driver
    final String driverName = "oracle.jdbc.driver.OracleDriver";
    Class.forName(driverName);
 
    // Connection parameters
    final String databaseHost = "hotsname";
    final String portNumber = "1521"; //Port on which oracle database is running
    final String sid = "dbname";
    final String url = "jdbc:oracle:thin:@" + databaseHost + ":" + portNumber + ":" + sid;
    final String username = "username";
    final String password = "password";
    connection = DriverManager.getConnection(url, username, password);
 
} catch (ClassNotFoundException e) {
    System.err.println("Unable to load the driver class, check your classpath.");
    e.printStackTrace();
} catch (SQLException e) {
    //Problem connecting to the database.
    System.err.println("Unable to connect to the database, check the connection parameters.");
    e.printStackTrace();    
}
 

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.