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();
        }
    }
  • 相关阅读:
    poj 2362 Square
    poj 1011 Sticks
    hust 1062 Divisibility
    hdu 4115 Eliminate the Conflict
    Android
    android stdio 快捷键
    Android Lint的使用
    Android studio导出配置
    fragment显示 Binary XML file line #12: Error inflating class fragment 错误
    markdown 字体颜色
  • 原文地址:https://www.cnblogs.com/linding/p/13839501.html
Copyright © 2011-2022 走看看