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();
        }
    }
  • 相关阅读:
    常用工具类
    手机端加载中
    jeecg的各种坑
    资源
    idea 破解后无法启动,我的配置文件搞错了
    eclipse xml 报某某.xsd找不到
    linux上部署svn服务器
    苹果手机微信浏览器无法通过post提交form数据
    %%%
    AtCoder arc060_d
  • 原文地址:https://www.cnblogs.com/linding/p/13839501.html
Copyright © 2011-2022 走看看