惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
C
Check Point Blog
博客园_首页
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
S
Security @ Cisco Blogs
L
LINUX DO - 最新话题
博客园 - 司徒正美
P
Privacy International News Feed
G
Google Developers Blog
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
K
Kaspersky official blog
I
InfoQ
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Webroot Blog
Webroot Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
量子位
H
Hacker News: Front Page
Simon Willison's Weblog
Simon Willison's Weblog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
SecWiki News
SecWiki News
S
Security Affairs
Latest news
Latest news
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
S
Security Archives - TechRepublic
V
Visual Studio Blog
T
Troy Hunt's Blog
S
Secure Thoughts
F
Fortinet All Blogs
V
V2EX
The Register - Security
The Register - Security
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - highmayor

在ABAP的SQL语句中写Oracle Hints Screen numbers ABAP 培训笔记 part 7 更改选择屏幕的GUI STATUS---RS_SET_SELSCREEN_STATUS 隐藏标准选择屏幕的执行按钮 SAP秀才-FI速成手册 FOR ALL ENTRIES的效率问题 - highmayor SAP学习笔记(HR Develepment学习笔记1) 程序间的调用 abap技术问题中文 - highmayor - 博客园 函数组的文件结构 - highmayor 闲说继承 oracle中使用SQL递归语句 - highmayor oracle删除重复行 深度理解按位异或运算符 一个容易忽略的陷阱:修改字符串常量的值 - highmayor - 博客园 使用sqlplus copy 命令在两个数据库间转移数据 Oracle数据库 Exp/Imp工具性能调优 算法的时间复杂度(计算实例)
通过JDBC操作ORACLE数据库
highmayor · 2010-05-30 · via 博客园 - highmayor

在ECLIPSE 中的项目属性的LIBRARY中导入C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar

package jdbc;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class JdbcOracle {
  public static void main(String[] args) {

    /**URL格式:drivername:@driver_information
       1,drivername主要有以下两种
       jdbc:oracle:thin (thin驱动程序)
       jdbc:oracle:oci (oci驱动程序)
       2,driver_information
       host_nameort:database_sid
     */

    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    String url = "jdbc:oracle:thin:@localhost:1521:ORADB";
    String username = "scott";
    String password = "tiger";
    try {

      /**一、注册驱动程序
          方法一Class.forName("oracle.jdbc.OracleDriver";
       */

      DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

      //二、打开数据库连接
      /**方法一,使用oracle数据源对象?
           oracle.jdbc.pool.OracleDataSource ds=new oracle.jdbc.pool.OracleDataSource();
          ds.setServerName("localhost";
          ds.setDatabaseName("ORADB";   //数据库存名
          ds.setDriverType("oci";  //要使用的JDBC驱动程序(OracleDatasore的扩展)
          ds.setURL("jdbc:oracle:thin:@localhost:1521:ORADB"; //指定数据库的URL(OracleDataSource的扩展)
          ds.setDataSourceName("";     //底层数据源的名称
          ds.setNetworkProtocol("tcp";//用于数据库通信的协议
          ds.setPortNumber(1521);//端口号
          ds.setUser("scott";
          ds.setPassword("tiger";
          Connection conn=ds.getConnection();
       */
      //方法二、使用Drivermanger

      conn = DriverManager.getConnection(url, username, password);

      //设置事务提交模式
      //conn.setAutoCommit(true);
      //若禁止了自动提交模式,那么在关闭Connection对象时会执行一次自动隐式提交,以保证还没有提交的所有DML语句被自动提交

      conn.setAutoCommit(false);

      //三、创建JDBC Statement对象

      stmt = conn.createStatement();

      //PreparedStatement pstmt=conn.prepareStatement("带有参数的SQL语句";
      //CallableStatement cstmt=conn.prepareCall("调用存储过程的语句";
      //四、从数据库获取行
      /**select 语句用executeQuery()
          insert,update,delete语句用executeUpdate()
          若预先不知道要执行的SQL语句类型,那么用execute()
       */

      rs = stmt.executeQuery("select id,name,age,sex,birth from employee";

//五、从数据库获取行

      while (rs.next()) {
        int id = rs.getInt("id";
        String name = rs.getString("name";
        int age = rs.getInt("age";
        String sex = rs.getString("sex";
        Date birth = rs.getDate("birth";
      }
      //rs.close();
      //六、向数据库中添加行(注:月份的编码是从0开始的,因此月份1代表2月)

      java.sql.Date date = new java.sql.Date(82, 10, 05);
      int i = stmt.executeUpdate("insert into employee values" +
                                 "(1,'qds',22,'1',TO_DATE(date,'YYYY,MM,DD'))";
      //七、修改数据中的行

      int j = stmt.executeUpdate("update employee set age=21 where id=1";
      //八、从数据库中删除行

      int k = stmt.executeUpdate("delete from employee set id=1";
      //九、处理数据库的NULL值方法一:使用结果集对象的wasNull方法判断


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cyz1980/archive/2006/01/11/575929.aspx