JDBC driver connection URL
This section describes the connection URL format and how to create connection objects with the drivermanager class.
If you want to use the drivermanager class to create connection objects, you need to know how to make a connection URL that provides access information to the Oracle server. the Oracle connection URL for the thin client-side driver ojdbc14.jar has the following format:
JDBC: oracle: thin: [user/password] @ [host] [: Port]: sidjdbc: 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: xejdbc: oracle: thin: herong/topsecret @: 1521: xejdbc: oracle: thin: herong/topsecret @ // localhost: 1521/xejdbc: oracle: thin: herong/topsecret @ //: 1521/xejdbc: oracle: thin: herong/topsecret @ // localhost/xejdbc: oracle: thin: herong/topsecret @ // XE
I wrote the following program to validate some of the connection URLs listed above:
/*** Oracleconnectionurl. java * copyright (c) 2007 by Dr. herong Yang. all rights reserved. */import Java. SQL. *; public class oracleconnectionurl {public static void main (string [] ARGs) {connection con = NULL; try {// load the oracle JDBC Driver Class. forname ("oracle. JDBC. oracledriver "); system. out. println ("oracle JDBC driver loaded OK. "); con = drivermanager. getconnection ("JDBC: oracle: thin: herong/topsecret @ localhost: 1521: XE"); system. out. println ("connected with @ localhost: 1521: Xe. "); con. close (); con = drivermanager. getconnection ("JDBC: oracle: thin: herong/topsecret @: 1521: XE"); system. out. println ("connected with @: 1521: Xe. "); con. close (); con = drivermanager. getconnection ("JDBC: oracle: thin: herong/topsecret @ // localhost: 1521/XE"); system. out. println ("connected with @/localhost: 1521/Xe. "); con. close (); con = drivermanager. getconnection ("JDBC: oracle: thin: herong/topsecret @ //: 1521/XE"); system. out. println ("connected with @ //: 1521/Xe. "); con. close (); con = drivermanager. getconnection ("JDBC: oracle: thin: herong/topsecret @ // localhost/XE"); system. out. println ("connected with @ // localhost/Xe. "); con. close (); con = drivermanager. getconnection ("JDBC: oracle: thin: herong/topsecret @ // XE"); system. out. println ("connected with @ // Xe. "); con. close (); con = drivermanager. getconnection ("JDBC: oracle: thin: herong/topsecret @ // localhost: 1521"); system. out. println ("connected with @ // localhost: 1521. "); con. close ();} catch (exception e) {system. err. println ("exception:" + E. getmessage ());}}}
Here is the output:
C: \> javac oracleconnectionurl. javac: \> JAVA-CP .; \ Local \ Lib \ ojdbc14.jar oracleconnectionurloracle JDBC driver loaded OK. connected with @ localhost: 1521: Xe. connected with @: 1521: Xe. connected with @ // localhost: 1521/Xe. connected with @ //: 1521/Xe. connected with @ // localhost/Xe. connected with @ // Xe. exception: Listener refused the connection with the following error: ORA-12514, TNS: Listener does not currently know of Service requested in connectdescriptorthe connection descriptor used by the client was: // localhost: 1521
The last URL test failed, because Sid was not specified. The Oracle HTTP listener cocould not connect the request to a database service, the SID.