Connecting to an Oracle Database

This example uses an Oracle JDBC driver to connect to an Oracle database instance located at 128.0.0.0:1521 with an sid called mydatabase.
Connection connection = null; try { // Load the JDBC driver String driverName = "oracle.jdbc.driver.OracleDriver"; Class.forName(driverName); // Create a connection to the database String serverName = "127.0.0.1"; String portNumber = "1521"; String sid = "mydatabase"; String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid; String username = "username"; String password = "password"; connection = DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { // Could not find the database driver } catch (SQLException e) { // Could not connect to the database }

Comments

11 Jan 2010 - 2:01am by Anonymous (not verified)

I set
catch (ClassNotFoundException e) {
return ("Could not find the database driver");
}

and I get
Method returned
java.lang.String : "Could not find the database driver"

I must copy to a directory ojdbc14.jar, where must be that?

Thanks

18 Jan 2010 - 10:40pm by Pratik (not verified)

Great Work. helped me for sure.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.