Connecting to Oracle Database using JDBC
Submitted by Duke on Wed, 08/15/2007 - 11:49
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