Java调用Oracle存储过程


Java调用Oracle存储过程:

import java.sql.*;
public class OracleProcedure {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  try {
   //加载驱动
   Class.forName("oracle.jdbc.driver.OracleDriver"); 
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  Connection con = null;
  CallableStatement cs = null;
  try {
   //得到连接
   con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl","scott","tiger");
   //创建CallableStatement对象
   cs = con.prepareCall("{call fly_pro3(?,?)}");
   //对参数赋值
   cs.setString(1, "SMITH");
   cs.setDouble(2, 1500.0);
   //执行存储过程调用
   cs.execute();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
   //关闭资源
   try {
    cs.close();
   } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   try {
    con.close();
   } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }

}

相关内容