zoukankan      html  css  js  c++  java
  • oracle pl/sql之在java中调用带有输入输出参数的oracle存储过程

    只需注意一点输出参数是用CallableStatement里面的registerOutParameter方法注册进去

    存储过程:

    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.sql.Types;

    //在java中调用oracle的存储过程
    public class JavaCallpro {

    public static void main(String[] args) {
      String driver="oracle.jdbc.driver.OracleDriver";
      String url="jdbc:oracle:thin:@127.0.0.1:1521:orcl";
      String user="scott";
      String password="ztoracle";
      try {
        Class.forName(driver);
        Connection c=DriverManager.getConnection(url, user, password);
        CallableStatement cs=c.prepareCall("{call my_pro(?,?,?)}");
          cs.setString(1, "9527");
          cs.registerOutParameter(2, Types.VARCHAR);
          cs.registerOutParameter(3, Types.VARCHAR);
          cs.execute();
        System.out.println(cs.getString(2));
    } catch (ClassNotFoundException e) {
    throw new RuntimeException();
    } catch (SQLException e) {

    }
    }

    }

  • 相关阅读:
    lnmp分离部署
    Nginx
    Keepalived脑裂监控
    KVM虚拟化
    mysql中间件proxysql实现mysql读写分离
    分离部署lnmp
    nginx
    Keepalived脑裂监控
    keepalived高可用
    KVM虚拟化
  • 原文地址:https://www.cnblogs.com/ztyy04126/p/4901548.html
Copyright © 2011-2022 走看看