zoukankan      html  css  js  c++  java
  • oracle java api

    一、项目结构

    二、代码

    import oracle.jdbc.OracleType;
    import org.junit.Test;
    
    import java.sql.*;
    
    public class myApplication {
        /**
         * 测试java连接oracle
         * @throws Exception
         */
        @Test
        public void test01() throws Exception {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "c##linlong", "123456");
    
            PreparedStatement statement = connection.prepareStatement("select * from person where pid = ?");
            statement.setObject(1, 4);
            ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()) {
                System.out.println(resultSet.getString("pname"));
            }
    
            resultSet.close();
            statement.close();
            connection.close();
        }
    
        /**
         * 调用存储过程
         * @throws Exception
         */
        @Test
        public void test02() throws Exception {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "c##linlong", "123456");
    
            CallableStatement statement = connection.prepareCall("{call protestout(?,?)}");
            statement.setObject(1, "孟美岐");
            statement.registerOutParameter(2, OracleType.VARCHAR2);
            statement.execute();
            System.out.println(statement.getObject(2));
    
            statement.close();
            connection.close();
        }
    
        /**
         * 调用存储函数
         * @throws Exception
         */
        @Test
        public void test03() throws Exception {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "c##linlong", "123456");
    
            CallableStatement statement = connection.prepareCall("{?=call sumpersonpidfun(?)}");
            statement.setObject(2, 4);
            statement.registerOutParameter(1, OracleType.NUMBER);
            statement.execute();
            System.out.println(statement.getObject(1));
    
            statement.close();
            connection.close();
        }
    }
  • 相关阅读:
    SQL Server 2008 R2英文版安装图解
    浅析在C#里面抛出SAP里面自定义的异常信息
    JavaScript中的函数基础
    《冷眼看IT》读书笔记IT将成为服务行业
    JavaScript入门
    IT成为第五个服务业
    JavaScript中匿名函数的困惑
    自定义的html radio button的样式
    探索客户端JavaScript
    JavScript中的循环
  • 原文地址:https://www.cnblogs.com/linding/p/13839501.html
Copyright © 2011-2022 走看看