Oracle JDBC connection string URL

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.