List of usage examples for java.sql CallableStatement setObject
default void setObject(String parameterName, Object x, SQLType targetSqlType) throws SQLException
From source file:com.adaptris.jdbc.StoredProcedure.java
private void applyInParameters(CallableStatement statement) throws SQLException { for (StoredProcedureParameter param : getParameters()) { if (param.getParameterType().equals(ParameterType.IN) || param.getParameterType().equals(ParameterType.INOUT)) { if (!isEmpty(param.getName())) { statement.setObject(param.getName(), param.getInValue(), param.getParameterValueType().getValue()); log.debug("Applying 'IN' parameter with name '" + param.getName() + "' and value '" + param.getInValue() + "'"); } else { statement.setObject(param.getOrder(), param.getInValue(), param.getParameterValueType().getValue()); log.debug("Applying 'IN' parameter with order '" + param.getOrder() + "' and value '" + param.getInValue() + "'"); }//from w w w. j a v a2 s . c om } if (param.getParameterType().equals(ParameterType.OUT) || param.getParameterType().equals(ParameterType.INOUT)) { if (!isEmpty(param.getName())) { statement.registerOutParameter(param.getName(), param.getParameterValueType().getValue()); log.debug("Registering 'OUT' parameter with name '" + param.getName() + "'"); } else { statement.registerOutParameter(param.getOrder(), param.getParameterValueType().getValue()); log.debug("Registering 'OUT' parameter with order '" + param.getOrder() + "'"); } } } }
From source file:org.silverpeas.dbbuilder.sql.QueryExecutor.java
public static void executeProcedure(Connection connection, String procedureName, DbProcParameter[] dbProcParameters) throws SQLException { StringBuilder preparedStatement; int i;/*from www . j a v a 2s . c o m*/ if (dbProcParameters == null || dbProcParameters.length == 0) { preparedStatement = new StringBuilder("{call " + procedureName + '}'); } else { preparedStatement = new StringBuilder("{call " + procedureName + '('); for (i = 0; i < dbProcParameters.length; i++) { preparedStatement.append('?'); if (i != (dbProcParameters.length - 1)) { preparedStatement.append(','); } } preparedStatement.append(")}"); } CallableStatement call = connection.prepareCall(preparedStatement.toString()); if (dbProcParameters != null) { for (i = 0; i < dbProcParameters.length; i++) { DbProcParameter dbPP = dbProcParameters[i]; call.setObject(i + 1, dbPP.getParameterValue(), dbPP.getParameterType()); if (dbPP.getIsOutParameter()) { call.registerOutParameter(i + 1, dbPP.getParameterType()); } } } call.execute(); if (dbProcParameters != null) { for (i = 0; i < dbProcParameters.length; i++) { if (dbProcParameters[i].getIsOutParameter()) { dbProcParameters[i].setParameterValue(call.getObject(i + 1)); } } } call.close(); }
From source file:org.vulpe.model.dao.impl.jpa.AbstractVulpeBaseDAOJPA.java
public CallableStatement executeCallableStatement(final String name, final Integer returnType, final List<Parameter> parameters) throws VulpeApplicationException { CallableStatement cstmt = null; try {//from ww w . j a v a2 s . c o m final Session session = (Session) entityManager.getDelegate(); final SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) session .getSessionFactory(); final ConnectionProvider connectionProvider = sessionFactoryImplementor.getConnectionProvider(); final Connection connection = connectionProvider.getConnection(); final StringBuilder call = new StringBuilder(); call.append(returnType == null ? "{call " : "{? = call "); call.append(name); int count = 0; if (parameters != null) { call.append("("); do { if (count > 0) { call.append(","); } call.append("?"); ++count; } while (count < parameters.size()); call.append(")"); } call.append("}"); if (parameters != null) { cstmt = connection.prepareCall(call.toString()); if (returnType != null) { if (returnType != 0) { cstmt.registerOutParameter(1, returnType); count = 1; } else { count = 0; } } for (Parameter parameter : parameters) { ++count; if (parameter.getType() == Types.ARRAY) { // Connection nativeConnection = // cstmt.getConnection().getMetaData().getConnection(); // ArrayDescriptor objectArrayDescriptor = // ArrayDescriptor.createDescriptor( // parameter.getArrayType(), nativeConnection); // Array array = new ARRAY(objectArrayDescriptor, // nativeConnection, parameter // .getArrayValues()); // cstmt.setArray(count, array); LOG.info(""); } else { cstmt.setObject(count, parameter.getValue(), parameter.getType()); } if (parameter.isOut()) { if (parameter.getType() == Types.ARRAY) { cstmt.registerOutParameter(count, Types.ARRAY, parameter.getArrayType()); } else { cstmt.registerOutParameter(count, parameter.getType()); } } } } cstmt.execute(); } catch (SQLException e) { throw new VulpeApplicationException(e.getMessage()); } return cstmt; }