欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

低版本jdbc连接高版本oracle,转:oracle11g的JDBC连接 URL和之前的版本有一定的区别...

发布时间:2023/11/27 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 低版本jdbc连接高版本oracle,转:oracle11g的JDBC连接 URL和之前的版本有一定的区别... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

今天安装了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:@");

where 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:@");

where is either a string

of the form

//:/,

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();

------------------------------------------------------------------------

还是得好好看原始文档啊!

但是还是不明白,为什么突然要改变呢?

总结

以上是生活随笔为你收集整理的低版本jdbc连接高版本oracle,转:oracle11g的JDBC连接 URL和之前的版本有一定的区别...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。

欢迎分享!

转载请说明来源于"生活随笔",并保留原作者的名字。

本文地址:低版本jdbc连接高版本oracle,转:oracle11g