1.首先先建立一个项目DB,右键点击DB,选择Build Path-->Configure Build Path进入

通过Add External JARs..选择D:\orcl\app\hr\product\11.2.0\dbhome_1\owb\wf\lib下的ojdbc14.jar,点击ok。

2.编写ConnectOracle.java文件

package com.wuy;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectOracle {

private Connection con;
 private String user="scott";
 //private String user = "sys as sysdba";
 private String password="18233188050";
 private String className="oracle.jdbc.driver.OracleDriver";
 //private String url="jdbc:oracle:oci@localhost:1158:orcl";这个url可能无效
 private String url = "jdbc:oracle:thin:@hr-PC:1521:orcl";hr-PC和1521很关键,也就是侦听串里有没有这个,在
D:\orcl\app\hr\product\11.2.0\dbhome_1\NETWORK\ADMIN\tnsnames.ora这个文件里有没有,一定要根据tnsnames.ora这个文件来配置url路径,否则会出错!!!


 public ConnectOracle(){
  try{
   Class.forName(className);
   System.out.println("加载数据库驱动成功!");
  }catch(ClassNotFoundException e){
   System.out.println("加载数据库驱动失败!");
   e.printStackTrace();
  }
 }

/**创建数据库连接*/
 public Connection getCon(){
  try {
   con=DriverManager.getConnection(url,user,password);
   System.out.println("创建数据库连接成功!");
  } catch (SQLException e) {
   System.out.print(con);
   System.out.println("创建数据库连接失败!");
   con=null;
   e.printStackTrace();
  }
  return con;
 }

public void closed(){
  try{
   if(con!=null){
    con.close();
   }
  }catch(SQLException e){
   System.out.println("关闭con对象失败!");
   e.printStackTrace();
  }
 }

public static void main(String[] args)
 {
  ConnectOracle c=new ConnectOracle();
  c.getCon();
  c.closed();
 }
}

3.运行结果:

eclipse如何连接oracle 11g数据库的更多相关文章

  1. VS2010 VS2012 如何连接Oracle 11g数据库

    oracle是开发者常用的数据库,在做.NET开发是,由于Vs自带的驱动只能连接oracle 10g及以下版本,那么如何连接oracle 11g呢? 工具/原料   事先安装VS2010或者VS201 ...

  2. PL/SQL Developer工具包和InstantClient连接Oracle 11g数据库

    一.前言 PLSQL Developer是Oracle数据库开发工具,很牛也很好用,PLSQL Developer功能很强大,可以做为集成调试器,有SQL窗口,命令窗口,对象浏览器和性能优化等功能. ...

  3. 11 vs2015 连接oracle 11g 数据库及相关问题

    1.下载Oracle Developer Tools for Visual Studio 2015 ,网址如下. http://www.oracle.com/technetwork/topics/do ...

  4. NaviCat Primium远程连接Oracle 11g数据库操作方法

    说明:作者使用的系统是windows 10 64位系统,使用的软件及插件都是基于64位系统进行安装.一. 软件准备 1.windows 10 64位 操作系统 2.NaviCat Primium 11 ...

  5. 使用instantclient_11_2 和PL/SQL Developer工具包连接oracle 11g远程数据库

    本文转自CSDN博客,http://blog.csdn.net/helifengwell/archive/2010/08/18/5820434.aspx 1,先到Oracle站点下载Instant C ...

  6. 本机不安装Oracle客户端,使用PL/SQL Developer和 Instant Client 工具包连接oracle 11g远程数据库

    一.先到Oracle网站下载Instant Client 下载地址:http://www.oracle.com/technetwork/cn/database/features/instant-cli ...

  7. 使用instantclient_11_2 和PL/SQL Developer工具包连接oracle 11g远程数据库(转)

    1,先到Oracle网站下载Instant Client : http://www.oracle.com/technology/global/cn/software/tech/oci/instantc ...

  8. c# Oracle 远程连接方式 plsql 连接oracle 11g 64位

    1.本地连接字符串:   string connect = "Data Source=orcl;user=XXX;password=XXX;Persist Security Info=Tru ...

  9. DBCP连接Oracle,数据库重启后现OALL8 is in an inconsistent state异常

    最近,DBCP连接Oracle,数据库重启后现OALL8 is in an inconsistent state异常. 版本说明 commons-dbcp-1.4.jar commons-pool-1 ...

随机推荐

  1. 知名黑客组织Anonymous(匿名者)的装备库

    原文出处: infosecinstitute   译文出处:freebuf   欢迎分享原创到伯乐头条 本文关注的是世界著名的黑客组织Anonymous(匿名者).“我将描述他们的攻击方法和方式的计划 ...

  2. javaScript内置类Date,Math等

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     & ...

  3. for循环语句以及迭代法和穷举法

    循环语句: 四要素:初始条件,循环条件,状态改变,循环体 for(初始条件;循环条件;状态改变){ //循环体} 案例1:打印等腰直角三角形和菱形 左上三角 static void Main(stri ...

  4. CommonJS规范(转)

    概述 CommonJS是服务器端模块的规范,Node.js采用了这个规范. 根据CommonJS规范,一个单独的文件就是一个模块.加载模块使用require方法,该方法读取一个文件并执行,最后返回文件 ...

  5. php include

    get_include_path  获取当前 include_path 配置选项的值,在当前代码目录未找到include文件时,则到include_path去include. set_include_ ...

  6. Struts+Spring+Hibernate整合入门详解

    Java 5.0 Struts 2.0.9 Spring 2.0.6 Hibernate 3.2.4 作者:  Liu Liu 转载请注明出处 基本概念和典型实用例子. 一.基本概念       St ...

  7. Understanding Virtual Memory

    Understanding Virtual Memory by Norm Murray and Neil Horman Introduction Definitions The Life of a P ...

  8. C#压缩图片1

    using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Drawing2D;us ...

  9. 利用K2和Microsoft Dynamics CRM构建业务App的5大理由

    Microsoft Dynamics CRM提供了一个绝佳的客户关系管理平台,使您能够创建各种以客户为中心的解决方案.然而,通过将K2的企业业务流程功能与Microsoft Dynamics CRM相 ...

  10. CCNA 4.14 TP Correction

    All people seem to need data processing ( Application presentation session transport network data li ...