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就行了

ojdbc6.rar下载

linux 下 java 链接oracle数据库的更多相关文章

  1. Linux下自动备份Oracle数据库并删除指定天数前的备份

    说明: Oracle数据库服务器 操作系统:CentOS IP:192.168.0.198 端口:1521 SID:orcl Oracle数据库版本:Oracle11gR2 具体操作: 1.root用 ...

  2. Aix/Linux下自动备份oracle数据库

    曾经有个同事,来回操作开发和生产的数据库,结果误删了生产的数据库,那种心情我想不是一般人能理解的,虽然说oracle可以有方法还原,但并不是彻底的. 所以,在工作中,不管是开发还是维护,备份数据库是非 ...

  3. linux下occi操作oracle数据库,中文乱码的问题

    转载:http://www.linuxidc.com/Linux/2008-02/11238.htm 前几日调通了OCI连接数据库的问题后,用Oracle自带的例子测试了一下,能正常读取数据(都是英文 ...

  4. Linux下oracle11gR2系统安装到数据库建立配置及最后oracle的dmp文件导入一站式操作记录

    简介 之前也在linux下安装过oralce,可每次都是迷迷糊糊的,因为大脑一片空白,网上随便看见一个文档就直接复制,最后搞了乱七八糟,虽然装上了,却乱得很,现在记录下来,希望能给其他网上朋友遇到问题 ...

  5. Java连接Oracle数据库的三种连接方式

    背景: 这两天在学习Oracle数据库,这里就总结下自己上课所学的知识,同时记录下来,方便整理当天所学下的知识,也同时方便日后自己查询. SQL语句的话,这里我就不多讲了,感觉和其他的数据库(MySQ ...

  6. Java JDBC链接Oracle数据库

    package com.test.test; import java.io.FileInputStream;import java.io.FileNotFoundException;import ja ...

  7. Oracle 远程链接oracle数据库服务器的配置

    远程链接oracle数据库服务器的配置 by:授客 QQ:1033553122 原理: 一.Oracle客户端与服务器端的通讯机制 1.OracleNet协议 如下图所示,Oracle通过Oracle ...

  8. Linux下java/bin目录下的命令集合

    Linux下JAVA命令(1.7.0_79) 命令 详解 参数列表 示例 重要程度 资料 appletviewer Java applet 浏览器.appletviewer 命令可在脱离万维网浏览器环 ...

  9. 关于vs2008使用oracleclient链接oracle数据库报报错OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用

    用vs2008链接oracle数据库出现问题,报错OCIEnvCreate 失败,返回代码为 -1,但错误消息文本不可用,从网上找了好久方法,有两种oracle客户端文件权限,和运行vs2008以管理 ...

随机推荐

  1. Ext3.4实现增删查改(form版)

    var TaskPolicyStore = new Ext.data.JsonStore( {    autoLoad : false,    url : 'PolicyServlet?method= ...

  2. 理解Java动态代理(1)—找我还钱?我出钱要你的命

    代理模式是最常用的一个设计模式之一,理解起来也是很简单,一张图足以说明了,LZ就不废话了. 至于代理模式能干嘛也不是LZ今天想说的,今天主要想简单介绍下JAVA里面的动态代理.“动”当然是相对“静”来 ...

  3. 使用mysqldiff生成两个数据库结构不同的脚本

    1,全库比较各个表的不同,并输出到文件 mysqldiff --server1=root:root@localhost --server2=root:root@localhost --difftype ...

  4. ubuntu 系统启动异常之无登录界面和版本号启动四个点的地方卡住

    zlib 搞的鬼,还没结局,由于rtmpdump 安装需要安装独立zlib库,装完后重启,完了吓一跳,卡住,尼玛这一年的代码都在里面啊!!! ldd /usr/sbin/python 查询库依赖zli ...

  5. (转)关于linux挂载window下共享文件

    关于linux挂载window下共享文件的方法: ①事先建立linux下文件夹,例如“ /mnt/linux-folder”②用mount命令挂载    mount -o username=windo ...

  6. update-alternatives常用命令(转自http://blog.csdn.net/baggio1006/article/details/6338623)

    Linux 发展到今天,可用的软件已经非常多了.这样自然会有一些软件的功能大致上相同.例如,同样是编辑器,就有 nvi.vim.emacs.nano,而且我说的这些还只是一部分.大多数情况下,这样的功 ...

  7. python_程序模拟浏览器请求及会话保持

    python下读取一个页面的数据可以通过urllib2轻松实现请求 import urllib2 print urllib2.urlopen('http://www.baidu.com').read( ...

  8. ASM - ByteCode插件下载、安装以及相关遇到的问题

    http://asm.ow2.org/eclipse/index.html http://download.forge.objectweb.org/eclipse-update/ http://for ...

  9. 安卓开发笔记——Fragment+FragmentTabHost组件(实现新浪微博底部菜单)

    记得之前写过2篇关于底部菜单的实现,由于使用的是过时的TabHost类,虽然一样可以实现我们想要的效果,但作为学习,还是需要来了解下这个新引入类FragmentTabHost 之前2篇文章的链接: 安 ...

  10. bootstrapValidator 表单验证

    官网下载地址:http://plugins.jquery.com/bootstrapValidator/ html代码 <!DOCTYPE html> <html> <h ...