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();
        }
    }
  • 相关阅读:
    linux系统下抢占式内核与非抢占式内核的区别
    Cache映射
    Delphi利用系统环境变量获取常用系统目录
    visual studio2008中AJAX的安装配置,及错误!
    网站配置工具无法建立与数据库的连接的解决方案
    PowDesigner工具的使用
    近日网站开发收获(一)
    (转载)power designer 12.5和破解补丁下载
    《Sqlserver 之我的新大陆》
    学习之路
  • 原文地址:https://www.cnblogs.com/linding/p/13839501.html
Copyright © 2011-2022 走看看