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 - 3: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 - 11:40pm by Pratik (not verified)

Great Work. helped me for sure.

6 May 2010 - 2:47am by Prashant Srivastav (not verified)

please tell me about odbc connection with java

9 Jul 2010 - 1:49pm by Eugenio (not verified)

Perdón por el español, pero muchas gracias me sirvió mucho su ejemplo.

19 Jul 2010 - 1:04am by plesianthropus (not verified)

Good work!

28 Jul 2010 - 12:46am by Anonymous (not verified)

Nice..............

18 Aug 2010 - 12:55pm by sky-fashion.net (not verified)

that is work

24 Aug 2010 - 1:48am by Anonymous (not verified)

Cheapest Name Brand New backpack designer Handbags bags fashion clothing wholesale from China www.besoso.com

24 Aug 2010 - 1:51am by Anonymous (not verified)
1 Sep 2010 - 10:32pm by vasu (not verified)

good! it's work well...

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.