Java examples for java.sql:CallableStatement
execute Stored Procedure
//package com.java2s; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { public static void executeProcedure(String procedure) { Connection con1 = getConnection(); CallableStatement pre = null; try {/*w ww . j a va 2s . com*/ pre = con1.prepareCall(procedure); pre.execute(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { if (pre != null) pre.close(); release(null, null, con1); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static Connection getConnection() { String url = "jdbc:mysql://localhost/sse?user=root&password=root"; //"jdbc:oracle:thin:@127.0.0.1:1521:orcl"; String username = "root"; //"jyl"; String pwd = "manager"; //"jyl7123421"; Connection con = null; try { con = DriverManager.getConnection(url, username, pwd); } catch (Exception ex) { ex.printStackTrace(); } return con; } public static void release(ResultSet rs, Statement stmt, Connection con) { try { if (rs != null) rs.close(); } catch (Exception ex) { ex.printStackTrace(); } try { if (stmt != null) stmt.close(); } catch (Exception ex) { ex.printStackTrace(); } try { if (con != null) con.close(); } catch (Exception ex) { ex.printStackTrace(); } } }