与Oracle 11g&一起使用的jdbc jar jdk 1.6以及如何连接到数据库本身 [英] what jdbc jar to use with oracle 11g & jdk 1.6 and how to connect to the db itself

查看:107
本文介绍了与Oracle 11g&一起使用的jdbc jar jdk 1.6以及如何连接到数据库本身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java编写数据库访问器.该数据库位于Oracle 11g中,我对此绝对不熟悉,并且我拥有JDK 1.6.

I'm writing a database accessor in Java. The database is in Oracle 11g, of which I am absolutely not familiar, and I have JDK 1.6.

  1. ojdbc4.jar可以用于我的程序吗?我们不允许在办公室中连接到Internet,也无法下载ojdbc6.jar,该文件与我的设置更兼容.
  2. 我应该在Class.forName(String driver)和DriverManager.getConnection(String connectionURL)中放入什么字符串?我不知道驱动程序字符串和连接URL,因为它们(自然)看起来与MS SQL Server的驱动程序字符串和连接URL完全不同.

推荐答案

  1. Oracle将Jar与Oracle客户端或服务器安装捆绑在一起,可以在$ORACLE_HOME/jdbc/lib/ojdbc6.jar中找到.我总是用那个.

  1. Oracle bundle the Jar with the Oracle client or server installation and can be found in $ORACLE_HOME/jdbc/lib/ojdbc6.jar. I always use that one.

驱动程序类名称为oracle.jdbc.OracleDriver,URL为jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE.

The Driver classname is oracle.jdbc.OracleDriver and the URL is jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE.

这是一个示例(摘自此处):

Here's an example (taken from here):

import java.sql.*;
class Conn {
  public static void main (String[] args) throws Exception
  {
   Class.forName ("oracle.jdbc.OracleDriver");

   Connection conn = DriverManager.getConnection
     ("jdbc:oracle:thin:@//localhost:1521/orcl", "scott", "tiger");
                        // @//machineName:port/SID,   userid,  password
   try {
     Statement stmt = conn.createStatement();
     try {
       ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
       try {
         while (rset.next())
           System.out.println (rset.getString(1));   // Print col 1
       } 
       finally {
          try { rset.close(); } catch (Exception ignore) {}
       }
     } 
     finally {
       try { stmt.close(); } catch (Exception ignore) {}
     }
   } 
   finally {
     try { conn.close(); } catch (Exception ignore) {}
   }
  }
}

这篇关于与Oracle 11g&一起使用的jdbc jar jdk 1.6以及如何连接到数据库本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆