JAVA连接Oracle的代码

2016-02-19 15:40 1 1 收藏

今天图老师小编给大家介绍下JAVA连接Oracle的代码,平时喜欢JAVA连接Oracle的代码的朋友赶紧收藏起来吧!记得点赞哦~

【 tulaoshi.com - 编程语言 】

最新做了一个连接Oracle的代码,要配好环境变量: ClassPath=.;E:j2sdk14libools.jar;E:oracleora90jdbclibclasses12.zip
测试的电脑已经装好Oracle客户端,而且用SQLplus可以连接上。
/*
* This sample shows how to list all the names from the EMP table
*
* It uses the JDBC THIN driver.  See the same program in the
* oci8 samples Directory to see how to use the other drivers.
*/ // You need to import the Java.sql package to use JDBC
import java.sql.*; class Test
{
  public static void main (String args [])
       throws SQLException
  {
    // Load the Oracle JDBC driver
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
/* try{
  Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(Exception e){
  System.out.println("No Driver!");
}
*/
    // Connect to the database
    // You must put a database name after the @ sign in the connection URL.
    // You can use either the fully specified SQL*net syntax or a short cut
    // syntax as host:port:sid.  The example uses the short cut syntax.
    String url = "jdbc:oracle:thin:@172.28.31.85:1521:YIKATONG";
    String userName = "scott";
    String passWord = "tiger";     if (args.length 0) url = args[0];
    if (args.length 1) userName = args[1];
    if (args.length 2) password = args[2];
System.out.println(url);
System.out.println(userName);
System.out.println(password);
    Connection conn =
      DriverManager.getConnection (url, userName, password);     // Create a Statement
    Statement stmt = conn.createStatement ();    // Select the ENAME column from the EMP table
    ResultSet rset = stmt.executeQuery ("select * from Test");     // Iterate through the result and print the employee names
    while (rset.next ())
      System.out.println (rset.getString (1));
  }
}

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

来源:https://www.tulaoshi.com/n/20160219/1610158.html

延伸阅读
内容或简介: /** 调用数据库里的一个函数 一个函数本质上一个返回一个结果的存储过程,这个例子示范了怎么调用有in、out和in/out参数的函数 ***********************************/ CallableStatement cs; try { // 调用一个没有参数的函数; 函数返回 a VARCHAR // 预处理callable语句   cs = connection.prepareCall("{? = ca...
/* drop table varray_table; drop type num_varray; CREATE TYPE num_varray AS VARRAY(10) OF VARCHAR2(12) / CREATE TABLE varray_table (col1 num_varray); INSERT INTO varray_table VALUES (num_varray('你好', 'abc')); select * from varray_table; */ import Java.sql.*; import java.math.*; import Oracle.jdbc.dri...
标签: ASP
  操作系统 Windows 2000 sp4 装有IIS5.0以及Oracle 8i 症状:用oracle自带的工具能连上数据库,一切操作正常。 使用ASP的ADODB以及MSADORA来接连oracle数据库,提示TNS错误或TNS适配器不能工作。 但是使用VB的程就能工作。 直到后来怀疑是IIS用户的权限不够,检查时发现用户名与机器名不匹配,原来这台机器改过名字。 于是改成与...
1、用数据库软件(如:mysql)创建数据库,在数据库注册时用到的数据库名则为刚刚创建的数据 库,若为数据源名,则需ODBC配置。 2、将驱动程序放在D:\Tomcat 5.5\common\lib或相应的开发工具的lib下, 对D:\Tomcat 5.5\conf\web.xml修改,打开web.xml,在/web-app的前面添加以下内容: resource-ref descriptionDB Con...
标签: Web开发
create table test(test1 varchar(20),test2 varchar(20) 然后向这个表写入一条测试纪录 那么现在开始我们的jsp和数据库之旅吧。   testoracle.jsp如下: %@ page contentType="text/html;charset=gb2312"%    %@ page import="java.sql.*"% html    body &nb...

经验教程

215

收藏

84
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部