功能:

  1. 执行存储过程

 

知识点摘要:

  1. Java使用CallableStatement接口处理存储过程
  2. 它继承自PreparedStatement
  3. 创建:con.prepareCall("{call 存储过程名(?,?)}");
  4. 执行:cs.execute();

 

程序演示: 放大

  1. package com.cxy.jdbc;  
  2.   
  3. import java.sql.CallableStatement;  
  4. import java.sql.Connection;  
  5. import java.sql.DriverManager;  
  6.   
  7. /** 
  8.  * @author cxy @ www.cxyapi.com 
  9.  */  
  10. public class CallableStatementTest  
  11. {  
  12.     public static void main(String[] args)  
  13.     {  
  14.         try(  
  15.                 Connection con=DriverManager.getConnection("jdbc:mysql://localhost/dbtest""root""root");  
  16.                 CallableStatement cs=con.prepareCall("{call test(?,?)}");  
  17.            )  
  18.            {  
  19.                 cs.setInt(11);  
  20.                 cs.setString(2"test");  
  21.                 cs.execute();  
  22.            }catch(Exception e)  
  23.            {  
  24.            System.out.println("数据库操作出现异常");  
  25.        }  
  26.     }  
  27.   
  28. }