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.运行结果:
VS2010 VS2012 如何连接Oracle 11g数据库
oracle是开发者常用的数据库,在做.NET开发是,由于Vs自带的驱动只能连接oracle 10g及以下版本,那么如何连接oracle 11g呢? 工具/原料 事先安装VS2010或者VS201 ...
PL/SQL Developer工具包和InstantClient连接Oracle 11g数据库
一.前言 PLSQL Developer是Oracle数据库开发工具,很牛也很好用,PLSQL Developer功能很强大,可以做为集成调试器,有SQL窗口,命令窗口,对象浏览器和性能优化等功能. ...
11 vs2015 连接oracle 11g 数据库及相关问题
1.下载Oracle Developer Tools for Visual Studio 2015 ,网址如下. http://www.oracle.com/technetwork/topics/do ...
NaviCat Primium远程连接Oracle 11g数据库操作方法
说明:作者使用的系统是windows 10 64位系统,使用的软件及插件都是基于64位系统进行安装.一. 软件准备 1.windows 10 64位 操作系统 2.NaviCat Primium 11 ...
使用instantclient_11_2 和PL/SQL Developer工具包连接oracle 11g远程数据库
本文转自CSDN博客,http://blog.csdn.net/helifengwell/archive/2010/08/18/5820434.aspx 1,先到Oracle站点下载Instant C ...
本机不安装Oracle客户端,使用PL/SQL Developer和 Instant Client 工具包连接oracle 11g远程数据库
一.先到Oracle网站下载Instant Client 下载地址:http://www.oracle.com/technetwork/cn/database/features/instant-cli ...
使用instantclient_11_2 和PL/SQL Developer工具包连接oracle 11g远程数据库(转)
1,先到Oracle网站下载Instant Client : http://www.oracle.com/technology/global/cn/software/tech/oci/instantc ...
c# Oracle 远程连接方式 plsql 连接oracle 11g 64位
1.本地连接字符串: string connect = "Data Source=orcl;user=XXX;password=XXX;Persist Security Info=Tru ...
DBCP连接Oracle,数据库重启后现OALL8 is in an inconsistent state异常
最近,DBCP连接Oracle,数据库重启后现OALL8 is in an inconsistent state异常. 版本说明 commons-dbcp-1.4.jar commons-pool-1 ...
随机推荐
玩转Windows服务系列——命令行管理Windows服务
说到Windows服务的管理就不得不说通过命令行的方式管理Windows服务,因为无论是系统管理员,还是通过编程的方式调用cmd命令,命令行都是非常方便以及强大的工具. 接下来就看一下如何通过cmd命 ...
Vue in 2016
原文链接:Vue in 2016 Vue 作者尤雨溪对 Vue 在 2016 年的总结以及未来的展望 现在已经是2016的尾声了!在这过去的12个月里,Vue的持续增长速度已经超过了我的预期--这个项 ...
滚轮事件js
jane