oracle jdbc connection string URL
2011-11-22 23:56
246 查看
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:
Here are some example connection URLs:
I wrote the following program to validate some of the connection URLs listed above:
Here is the output:
The last URL test failed, because SID was not specified. The Oracle HTTP listener could not connect the request to a database service, the SID.
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]: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
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.java C:\>java -cp .;\local\lib\ojdbc14.jar OracleConnectionUrl Oracle 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 connect descriptor The Connection descriptor used by the client was: //localhost:1521
The last URL test failed, because SID was not specified. The Oracle HTTP listener could not connect the request to a database service, the SID.
相关文章推荐
- Cannot get connection for URL jdbc:oracle:thin:调用中无效参数
- Exception:com.mchange.v2.c3p0.impl.NewProxyConnection cannot be cast to oracle.jdbc.OracleConnection
- SSH框架Cannot create JDBC driver of class '' for connect URL 'jdbc:oracle:thin:@localhost:1521:你的数据库名'
- hibernate.connection.url和sqljdbc.jar
- PL/SQL可以连oracle,但是jdbc连不上,原来是因为url链接方式不同 格式不一样
- JDBC, SQLJ, Oracle JPublisher and Universal Connection Pool (UCP)
- Oracle中jdbc的url的双机写法和单机写法
- Oracle的JDBC Url的几种方式
- First time to create JDBC connection to ORACLE SQL
- 现在的连接url:Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useUnico
- 【HttpUrlConnection】自定义StreamToString--流转换成字符串(1.1)
- Oracle JDBC URL
- Could not resolve placeholder 'master.jdbc.url' in string value "${master.jdbc.url}"
- oracle.jdbc.OracleConnection.physicalConnectionWithin问题
- weblogic.jdbc.wrapper.Clob_oracle_sql_CLOB转换成String
- jdbc连接mysql,oracle的URL和DriverClass
- 在linux上通过JDBC连接ORACLE 时总是出现 java.sql.SQLRecoverableException: IO Error: Connection reset 的问题
- java通过JDBC访问Oracle的String异常
- Could not resolve placeholder 'jdbc.url' in string value "${jdbc.url}"
- 换成atomikos后报java.lang.AbstractMethodError: oracle.jdbc.driver.LogicalConnection.createClob()Ljava/sq