linux 下 java 链接oracle数据库
import java.sql.*; public class Hello {
private final String oracleDriverName = "oracle.jdbc.driver.OracleDriver";
private final String oracleUrlToConnect ="jdbc:oracle:thin:@00.00.00.00:1521:ics";
private Connection myConnection = null;
private final String loginName="db_xxxx";
private final String loginPassword="DB_xxxx"; public Hello()
{
try
{
Class.forName(oracleDriverName);
}
catch(ClassNotFoundException ex)
{
//System.out.println(getErrorMessage(ex,"The Driver loaded error,please contact to your Software Designer!").toString());
System.out.println(ex.getMessage()+"\n"+ex.getStackTrace());
}
} public StringBuffer getErrorMessage(Exception ex,String alarmMessage)
{
StringBuffer errorStringBuffer = new StringBuffer();
errorStringBuffer.append(alarmMessage);
errorStringBuffer.append(ex.getMessage());
return errorStringBuffer;
} /**
* getConnection method
* @return Connection
*/
public Connection getConnection()
{
try
{
this.myConnection = DriverManager.getConnection(oracleUrlToConnect,loginName,loginPassword);
//System.out.print("connection successfully");
}
catch(Exception ex)
{
//System.out.println(getErrorMessage(ex,"Can not get connection,please contact to your Software Designer!").toString());
System.out.println(ex.getMessage()+"\n"+ex.getStackTrace());
} return this.myConnection; } /**
* @param args
*/
public static void main(String[] args) {
Hello he = new Hello();
try
{
Connection conn = he.getConnection();
Statement stmt = conn.createStatement() ;
ResultSet rs =stmt.executeQuery("select xxx from tb_xxx where rownum<=5");
while(rs.next())
{
System.out.println(rs.getString(1));
}
//System.out.println("Now begin to excute.............");
if(rs != null){ // 关闭记录集
try{
rs.close() ;
}catch(SQLException e){
e.printStackTrace() ;
}
}
if(stmt != null){ // 关闭声明
try{
stmt.close() ;
}catch(SQLException e){
e.printStackTrace() ;
}
}
if(conn != null){ // 关闭连接对象
try{
conn.close() ;
}catch(SQLException e){
e.printStackTrace() ;
}
}
}
catch(Exception ex)
{
System.out.println(he.getErrorMessage(ex,"Application error,please contact to your Software Designer!").toString());
}
}
}
运行的时候需要执行ojdbc.rar文件,之前在window下运行没问题,但是放linux下运行老提示找不到加载不了数据库类,后来用eclipse把ojdbc.rar一起打包就行了
打包时要选择可运行的jar就行了
linux 下 java 链接oracle数据库的更多相关文章
- Linux下自动备份Oracle数据库并删除指定天数前的备份
说明: Oracle数据库服务器 操作系统:CentOS IP:192.168.0.198 端口:1521 SID:orcl Oracle数据库版本:Oracle11gR2 具体操作: 1.root用 ...
- Aix/Linux下自动备份oracle数据库
曾经有个同事,来回操作开发和生产的数据库,结果误删了生产的数据库,那种心情我想不是一般人能理解的,虽然说oracle可以有方法还原,但并不是彻底的. 所以,在工作中,不管是开发还是维护,备份数据库是非 ...
- linux下occi操作oracle数据库,中文乱码的问题
转载:http://www.linuxidc.com/Linux/2008-02/11238.htm 前几日调通了OCI连接数据库的问题后,用Oracle自带的例子测试了一下,能正常读取数据(都是英文 ...
- Linux下oracle11gR2系统安装到数据库建立配置及最后oracle的dmp文件导入一站式操作记录
简介 之前也在linux下安装过oralce,可每次都是迷迷糊糊的,因为大脑一片空白,网上随便看见一个文档就直接复制,最后搞了乱七八糟,虽然装上了,却乱得很,现在记录下来,希望能给其他网上朋友遇到问题 ...
- Java连接Oracle数据库的三种连接方式
背景: 这两天在学习Oracle数据库,这里就总结下自己上课所学的知识,同时记录下来,方便整理当天所学下的知识,也同时方便日后自己查询. SQL语句的话,这里我就不多讲了,感觉和其他的数据库(MySQ ...
- Java JDBC链接Oracle数据库
package com.test.test; import java.io.FileInputStream;import java.io.FileNotFoundException;import ja ...
- Oracle 远程链接oracle数据库服务器的配置
远程链接oracle数据库服务器的配置 by:授客 QQ:1033553122 原理: 一.Oracle客户端与服务器端的通讯机制 1.OracleNet协议 如下图所示,Oracle通过Oracle ...
- Linux下java/bin目录下的命令集合
Linux下JAVA命令(1.7.0_79) 命令 详解 参数列表 示例 重要程度 资料 appletviewer Java applet 浏览器.appletviewer 命令可在脱离万维网浏览器环 ...
- 关于vs2008使用oracleclient链接oracle数据库报报错OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用
用vs2008链接oracle数据库出现问题,报错OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用,从网上找了好久方法,有两种oracle客户端文件权限,和运行vs2008以管理 ...
随机推荐
- SpagoBI 教程 Lesson 1:Introduction and Installation
SapgoBI Lesson 1: Introduction and Installation Downloading and installing SpagoBI. Download SpagoBI ...
- Android WiFi 日志记录(ASSOC_REJECT)
记录Android N关联拒绝之后的相关的log. 10-26 20:35:35.844 2215 2215 D wpa_supplicant: * bssid_hint=44:48:c1:d6:57 ...
- zXing使用注意事项-转
zXing使用注意事项 ------------------ zxing和zbar的比较: ZXing项目的示例程序对于摄像头的控制写的非常全面,ZBar的没有ZBar基于C语言编写,解码效率高于 ...
- mysql -- 远程访问mysql的解决方案
1.改表法 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "u ...
- JsonObject和Gson详解
参考文件:http://www.cnblogs.com/xwdreamer/archive/2011/12/16/2296904.html一.JsonObject 1.JAR包简介 要使程序可以运行必 ...
- CentOS 7 安装、配置、使用 PostgreSQL 10 安装及基础配置
官网安装方法:https://www.postgresql.org/download/linux/redhat/ 卸载的话使用 yum remove 相应的安装 Install the reposit ...
- EJB里的问题解答
1.什么是EJB? EJB即Enterprise JavaBean是JavaEE应用的业务层技术标准,以这项技术开发的组件叫做EJB组件. EJB架构师一个用于开发和部署基于组件的分布式业务应用的组件 ...
- ARC介绍
从Ray Wenderlich的教程中截取了一小段作为对objective c中ARC的介绍,讲得比较清晰,原文有丰富的例子,见此 它是怎么工作的 你大概已经熟悉如何手工管理内存了, 就像这样:如果你 ...
- 基于maven使用IDEA创建多模块项目
原文地址:http://blog.csdn.net/williamhappy/article/details/54376855 鉴于最近学习一个分布式项目的开发,讲一下关于使用IntelliJ IDE ...
- Java常用数据结构之Set之TreeSet
前言 上篇文章我们分析了HashSet,它是基于HashMap实现的,那TreeSet会是怎么实现的呢?没错!和大家想的一样,它是基于TreeMap实现的.所以,TreeSet的源码也很简单,主要还是 ...