Here you can find the source of executeUpdateSP(Connection conn, String spName, Object... sqlParameters)
Parameter | Description |
---|---|
conn | : the connection that got the Stored Procedure |
spName | : stored peocedure call query e.g.: {call sp(?)} |
sqlParameters | : list filled with the stored procedure parameters |
public static int executeUpdateSP(Connection conn, String spName, Object... sqlParameters) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.*; public class Main { /** execute stored procedure *@param conn : the connection that got the Stored Procedure *@param spName : stored peocedure call query e.g.: {call sp(?)} *@param sqlParameters : list filled with the stored procedure parameters *@return : resultSet filled with the stored Procedure output *//*ww w . jav a 2s. c o m*/ public static int executeUpdateSP(Connection conn, String spName, Object... sqlParameters) throws SQLException { //setNullableParameters(sqlParameters); spName = getQueryString(spName, sqlParameters); int rs = 0; CallableStatement cs = null; if (conn != null) { cs = conn.prepareCall(spName); if (sqlParameters != null) { for (int i = 1; i <= sqlParameters.length; i++) { cs.setObject(i, sqlParameters[i - 1]); } } rs = cs.executeUpdate(); } return rs; } public static String getQueryString(String spName, Object[] sqlParameters) { String spName1 = "{call " + spName + "("; for (int i = 0; i < sqlParameters.length; i++) { spName1 += "?"; if (i < sqlParameters.length - 1) { spName1 += ","; } } spName1 += ")}"; return spName1; } }