List of usage examples for java.sql CallableStatement setInt
void setInt(String parameterName, int x) throws SQLException;
int
value. From source file:org.marccarre.spring.db.testing.FooDao.java
public List<Foo> getByIdCallableStatement(int id) { final int fooId = id; return jdbcTemplate.execute(new CallableStatementCreator() { public CallableStatement createCallableStatement(Connection con) throws SQLException { CallableStatement cs = con.prepareCall("{call GetFoosById(?)}"); cs.setInt(1, fooId); return cs; }//w ww . j a v a 2 s . c o m }, new CallableStatementCallback<List<Foo>>() { public List<Foo> doInCallableStatement(CallableStatement cs) throws SQLException { cs.execute(); List<Foo> foos = new ArrayList<Foo>(); if (cs.getMoreResults()) { ResultSet rs = cs.getResultSet(); FooRowMapper mapper = new FooRowMapper(); int rowIndex = 0; while (rs.next()) { foos.add(mapper.mapRow(rs, rowIndex)); rowIndex++; } } return foos; } }); }
From source file:de.whs.poodle.repositories.ExerciseWorksheetRepository.java
public void removeChapter(int chapterId) { jdbc.update(con -> {// w ww.j a v a 2 s.co m CallableStatement cs = con.prepareCall("{ CALL remove_chapter(?) }"); cs.setInt(1, chapterId); return cs; }); }
From source file:de.whs.poodle.repositories.ExerciseWorksheetRepository.java
public void moveChapter(int chapterId, boolean up) { jdbc.update(con -> {//w w w .j a v a 2 s . co m CallableStatement cs = con.prepareCall("{ CALL move_chapter(?,?) }"); cs.setInt(1, chapterId); cs.setBoolean(2, up); return cs; }); }
From source file:de.whs.poodle.repositories.ExerciseWorksheetRepository.java
public void addExerciseToChapter(int chapterId, int exerciseId) { jdbc.update(con -> {/* ww w. ja v a 2 s. co m*/ CallableStatement cs = con.prepareCall("{ CALL add_exercise_to_chapter(?,?,TRUE) }"); cs.setInt(1, chapterId); cs.setInt(2, exerciseId); return cs; }); }
From source file:de.whs.poodle.repositories.ExerciseWorksheetRepository.java
public void moveExercise(int chapterId, int exerciseId, boolean up) { jdbc.update(con -> {// w ww . j av a 2 s. c om CallableStatement cs = con.prepareCall("{ CALL move_exercise_in_worksheet(?,?,?) }"); cs.setInt(1, chapterId); cs.setInt(2, exerciseId); cs.setBoolean(3, up); return cs; }); }
From source file:jongo.jdbc.JDBCExecutor.java
/** * Utility method which registers in a CallableStatement object the different {@link jongo.jdbc.StoredProcedureParam} * instances in the given list. Returns a List of {@link jongo.jdbc.StoredProcedureParam} with all the OUT parameters * registered in the CallableStatement//from w w w . j a v a2 s . c om * @param cs the CallableStatement object where the parameters are registered. * @param params a list of {@link jongo.jdbc.StoredProcedureParam} * @return a list of OUT {@link jongo.jdbc.StoredProcedureParam} * @throws SQLException if we fail to register any of the parameters in the CallableStatement */ private static List<StoredProcedureParam> addParameters(final CallableStatement cs, final List<StoredProcedureParam> params) throws SQLException { List<StoredProcedureParam> outParams = new ArrayList<StoredProcedureParam>(); int i = 1; for (StoredProcedureParam p : params) { final Integer sqlType = p.getType(); if (p.isOutParameter()) { l.debug("Adding OUT parameter " + p.toString()); cs.registerOutParameter(i++, sqlType); outParams.add(p); } else { l.debug("Adding IN parameter " + p.toString()); switch (sqlType) { case Types.BIGINT: case Types.INTEGER: case Types.TINYINT: // case Types.NUMERIC: cs.setInt(i++, Integer.valueOf(p.getValue())); break; case Types.DATE: cs.setDate(i++, (Date) JongoUtils.parseValue(p.getValue())); break; case Types.TIME: cs.setTime(i++, (Time) JongoUtils.parseValue(p.getValue())); break; case Types.TIMESTAMP: cs.setTimestamp(i++, (Timestamp) JongoUtils.parseValue(p.getValue())); break; case Types.DECIMAL: cs.setBigDecimal(i++, (BigDecimal) JongoUtils.parseValue(p.getValue())); break; case Types.DOUBLE: cs.setDouble(i++, Double.valueOf(p.getValue())); break; case Types.FLOAT: cs.setLong(i++, Long.valueOf(p.getValue())); break; default: cs.setString(i++, p.getValue()); break; } } } return outParams; }
From source file:de.whs.poodle.repositories.CourseRepository.java
public void edit(Course course) { try {// w w w . j av a2 s . c om jdbc.update(con -> { CallableStatement cs = con.prepareCall("{ CALL update_course(?,?,?,?,?,?) }"); cs.setInt(1, course.getId()); cs.setString(2, course.getName()); cs.setBoolean(3, course.getVisible()); if (course.getPassword().trim().isEmpty()) cs.setNull(4, Types.VARCHAR); else cs.setString(4, course.getPassword()); Array otherInstructors = con.createArrayOf("int4", course.getOtherInstructorsIds().toArray()); cs.setArray(5, otherInstructors); Array linkedCourses = con.createArrayOf("int4", course.getLinkedCoursesIds().toArray()); cs.setArray(6, linkedCourses); return cs; }); } catch (DuplicateKeyException e) { throw new BadRequestException(); } }
From source file:de.whs.poodle.repositories.McWorksheetRepository.java
public void prepareMcStatistics(int studentId, int courseTermId, int mcWorksheetToQuestionId) { jdbc.update(con -> {/*from w w w . jav a 2 s . com*/ CallableStatement cs = con.prepareCall("{ CALL prepare_mc_statistic(?,?,?) }"); cs.setInt(1, studentId); cs.setInt(2, courseTermId); cs.setInt(3, mcWorksheetToQuestionId); return cs; }); }
From source file:de.whs.poodle.repositories.TagRepository.java
public void mergeTags(List<Integer> tagIds, int mergeTo) { jdbc.update(con -> {//from w w w .j av a2s. com CallableStatement cs = con.prepareCall("{ CALL merge_tags(?,?) }"); Array tagIdsArray = con.createArrayOf("int4", tagIds.toArray()); cs.setArray(1, tagIdsArray); cs.setInt(2, mergeTo); return cs; }); }
From source file:com.taobao.diamond.server.service.HangingModePersistService.java
/** * Returns a callable statement/*ww w.j a v a 2s . c om*/ * * @param conn * Connection to use to create statement * @return cs A callable statement */ public CallableStatement createCallableStatement(Connection conn) { StringBuffer storedProcName = new StringBuffer("call "); storedProcName.append(storedProc + "("); // set output parameters storedProcName.append("?"); storedProcName.append(")"); CallableStatement cs = null; try { // set the first parameter is OracleTyep.CURSOR for oracel stored // procedure cs = conn.prepareCall(storedProcName.toString()); cs.setInt(1, sleepTime); } catch (SQLException e) { throw new RuntimeException("createCallableStatement method Error : SQLException " + e.getMessage()); } return cs; }