Pages

Saturday, November 12, 2011

JDBC Driver URL Format for connection with Oracle


I got the idea of testing my connectivity through JDBC with Oracle, when my attempt to connect through Hibernate in a Struts application failed.
Really I wonder like any one else about what one’s mind can do to one. In my case here it was constructive. Atleast I got to learn something J

jdbc:oracle:thin:[user/password]@[host][:port]:SID
jdbc:oracle:thin:[user/password]@//[host][:port]/SID

  user - The login user name defined in the Oracle server.

  password - The password for the login user.

  host - The host name where Oracle server is running.
         Default is 127.0.0.1 - the IP address of localhost.

  port - The port number where Oracle is listening for connection.
         Default is 1521.

  SID  - System ID of the Oracle server database instance.
         SID is a required value. By default, Oracle Database 10g Express
         Edition creates one database instance called XE.

Here are some example connection URLs:

jdbc:oracle:thin: Herong/TopSecret @localhost:1521:XE
jdbc:oracle:thin:Herong/TopSecret@:1521:XE

jdbc:oracle:thin:Herong/TopSecret@//localhost:1521/XE
jdbc:oracle:thin:Herong/TopSecret@//:1521/XE
jdbc:oracle:thin:Herong/TopSecret@//localhost/XE
jdbc:oracle:thin:Herong/TopSecret@///XE

You can find more details about the same in http://www.herongyang.com/JDBC/Oracle-JDBC-Driver-Connection-URL.html. Seems to be a real nice site

The host, port and SID details can be found in tnsNames.ora file. Following is an illustration of the same


Hence the URL formats for me were like

jdbc:oracle:thin:Karthick/Password@10.106.50.250:1521:AGH
jdbc:oracle:thin: Karthick/Password @//10.106.50.250:1521/AGH


Hope this helps some one seeking for this out there :)

2 comments:

  1. Thanks it did sort my issue. I tried several known formats of JDBC URL but all throwed SQLException. This one did the trick

    Atish

    ReplyDelete