oracle11g的JDBC连接 URL和之前的版本有一定的区别
2013-03-28 21:43
393 查看
转自:http://blog.csdn.net/ttaaoo36/article/details/5651034
今天安装了oracle11g后,写了JDBC测试程序,一直都连接不上!
一直找不到原因
后来读了一下安装文件中的Readme.txt文档,汗啊!这个版本居然把url的访问方式改变了:
Some Useful Hints In Using the JDBC Drivers
-------------------------------------------
Please refer to "JDBC Developer's Guide and Reference" for details
regarding usage of Oracle's JDBC Drivers. This section only offers
useful hints. These hints are not meant to be exhaustive.
These are a few simple things that you should do in your JDBC program:
1. Import the necessary JDBC classes in your programs that use JDBC.
For example:
import java.sql.*;
import java.math.*; // if needed
To use OracleDataSource, you need to do:
import oracle.jdbc.pool.OracleDataSource;
2. Create an OracleDataSource instance.
OracleDataSource ods = new OracleDataSource();
3. set the desired properties if you don't want to use the
default properties. Different connection URLs should be
used for different JDBC drivers.
ods.setUser("my_user");
ods.setPassword("my_password");
For the JDBC OCI Driver:
To make a bequeath connection, set URL as:
ods.setURL("jdbc:oracle:oci:@");
To make a remote connection, set URL as:
ods.setURL("jdbc:oracle:oci:@<database>");
where <database> is either a TNSEntryName
or a SQL*net name-value pair defined in tnsnames.ora.
For the JDBC Thin Driver, or Server-side Thin Driver:
ods.setURL("jdbc:oracle:thin:@<database>");
where <database> is either a string of the form
//<host>:<port>/<service_name>, or a SQL*net name-value pair,
or a TNSEntryName.
For the JDBC Server-side Internal Driver:
ods.setURL("jdbc:oracle:kprb:");
Note that the trailing ':' is necessary. When you use the
Server-side Internal Driver, you always connect to the
database you are executing in. You can also do this:
Connection conn =
new oracle.jdbc.OracleDriver().defaultConnection();
4. Open a connection to the database with getConnection()
methods defined in OracleDataSource class.
Connection conn = ods.getConnection();
------------------------------------------------------------------------
还是得好好看原始文档啊!
但是还是不明白,为什么突然要改变呢?
今天安装了oracle11g后,写了JDBC测试程序,一直都连接不上!
一直找不到原因
后来读了一下安装文件中的Readme.txt文档,汗啊!这个版本居然把url的访问方式改变了:
Some Useful Hints In Using the JDBC Drivers
-------------------------------------------
Please refer to "JDBC Developer's Guide and Reference" for details
regarding usage of Oracle's JDBC Drivers. This section only offers
useful hints. These hints are not meant to be exhaustive.
These are a few simple things that you should do in your JDBC program:
1. Import the necessary JDBC classes in your programs that use JDBC.
For example:
import java.sql.*;
import java.math.*; // if needed
To use OracleDataSource, you need to do:
import oracle.jdbc.pool.OracleDataSource;
2. Create an OracleDataSource instance.
OracleDataSource ods = new OracleDataSource();
3. set the desired properties if you don't want to use the
default properties. Different connection URLs should be
used for different JDBC drivers.
ods.setUser("my_user");
ods.setPassword("my_password");
For the JDBC OCI Driver:
To make a bequeath connection, set URL as:
ods.setURL("jdbc:oracle:oci:@");
To make a remote connection, set URL as:
ods.setURL("jdbc:oracle:oci:@<database>");
where <database> is either a TNSEntryName
or a SQL*net name-value pair defined in tnsnames.ora.
For the JDBC Thin Driver, or Server-side Thin Driver:
ods.setURL("jdbc:oracle:thin:@<database>");
where <database> is either a string of the form
//<host>:<port>/<service_name>, or a SQL*net name-value pair,
or a TNSEntryName.
For the JDBC Server-side Internal Driver:
ods.setURL("jdbc:oracle:kprb:");
Note that the trailing ':' is necessary. When you use the
Server-side Internal Driver, you always connect to the
database you are executing in. You can also do this:
Connection conn =
new oracle.jdbc.OracleDriver().defaultConnection();
4. Open a connection to the database with getConnection()
methods defined in OracleDataSource class.
Connection conn = ods.getConnection();
------------------------------------------------------------------------
还是得好好看原始文档啊!
但是还是不明白,为什么突然要改变呢?
相关文章推荐
- java中使用jdbc配置连接串时mysql 5.6与5.7版本“编码”参数有区别!
- Maven + 各数据库连接driverClass、jdbcUrl、Maven依赖不完全记录
- Java-Jdbc,JDBC连接Oracle11g实例:
- 使用JDBC连接MSSQL数据库中2000/2005/2008的区别
- JDBC驱动下载及连接字符串URL写法汇总(java版)
- 使用TOMCAT5.5连接池连接mysql(解决Cannot create JDBC driver of class '' for connect URL 'null')
- Xcode6 模拟器路径和之前版本的区别
- JDBC与SQL SERVER各个版本的连接方法
- JDBC各种数据库的连接的URL
- 使用TOMCAT5.5连接池连接mysql(解决Cannot create JDBC driver of class '' for connect URL 'null')
- JDBC各种数据库连接字符串和URL
- HttpURLConnection和HttpClient两种连接方式的区别
- 数据库连接Driver Class和JDBC URL大全
- 关于转屏禁止onCreate android 3.0版本之前和之后的区别
- JDBC连接数据库的URL关键代码
- Java网络连接之HttpURLConnection与HttpClient 区别及联系
- Java网络连接之HttpURLConnection与HttpClient 区别及联系
- android 学习九 Fragments 介绍(android3.0及4.0与之前版本区别的部分)
- 各种数据库的JDBC驱动下载及连接字符串URL写法
- jdbc连接数据库使用sid和service_name的区别(转)