用于调用数据库的存储过程
1 import java.sql.CallableStatement; 2 import java.sql.Connection; 3 import java.sql.DriverManager; 4 import java.sql.PreparedStatement; 5 import java.sql.Types; 6 7 8 9 10 public class TestCallable { 11 12 /** 13 * @param args 14 */ 15 public static void main(String[] args) throws Exception{ 16 17 Connection conn = null; 18 Class.forName("oracle.jdbc.driver.OracleDriver"); 19 conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ELLENIOU", "scott", "tiger"); 20 21 //p为在数据库创建的过程 22 CallableStatement cs = conn.prepareCall("{call p(?,?,?,?)}"); 23 cs.registerOutParameter(3, Types.INTEGER); 24 cs.registerOutParameter(4, Types.INTEGER); 25 cs.setInt(1, 3); 26 cs.setInt(2, 4); 27 cs.setInt(4, 5); 28 cs.execute(); 29 System.out.println(cs.getInt(3)); 30 System.out.println(cs.getInt(4)); 31 cs.close(); 32 conn.close(); 33 34 } 35 36 }