use of org.springframework.jdbc.core.PreparedStatementCreator in project camel by apache.
the class ElsqlProducer method processStreamList.
protected void processStreamList(final Exchange exchange, final String sql, final SqlParameterSource param) throws Exception {
// spring JDBC to parse the SQL and build the prepared statement creator
// this is what NamedJdbcTemplate does internally
final ParsedSql parsedSql = NamedParameterUtils.parseSqlStatement(sql);
final String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, param);
final Object[] params = NamedParameterUtils.buildValueArray(parsedSql, param, null);
final List<SqlParameter> declaredParameters = NamedParameterUtils.buildSqlParameterList(parsedSql, param);
final PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(sqlToUse, declaredParameters);
final PreparedStatementCreator statementCreator = pscf.newPreparedStatementCreator(params);
processStreamList(exchange, statementCreator, sqlToUse);
}
use of org.springframework.jdbc.core.PreparedStatementCreator in project nixmash-blog by mintster.
the class GitHubTests method githubStatRecordKeyReturned.
@Test
public void githubStatRecordKeyReturned() throws Exception {
KeyHolder keyHolder = new GeneratedKeyHolder();
long statId = -1L;
try {
statId = jdbcTemplate.queryForObject("SELECT stat_id FROM github_stats WHERE stat_date = '2010-10-10'", Long.class);
} catch (EmptyResultDataAccessException e) {
jdbcTemplate.update(new PreparedStatementCreator() {
String INSERT_SQL = "INSERT INTO github_stats (stat_date) VALUES ('2010-10-10')";
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(INSERT_SQL, new String[] { "stat_id" });
return ps;
}
}, keyHolder);
statId = keyHolder.getKey().longValue();
}
assertThat(statId).isGreaterThan(0);
}
use of org.springframework.jdbc.core.PreparedStatementCreator in project bitcampSCOpen2017 by ryuyj.
the class MemberDao method insert.
public // 생명주기가 다르기 때문에 final로 지정
void insert(// 생명주기가 다르기 때문에 final로 지정
final Member member) {
KeyHolder keyHolder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement pstmt = con.prepareStatement("INSERT INTO MEMBER (EMAIL, PASSWORD, NAME, REGDATE, PHOTO) VALUES (?, ?, ?, ?, ?)", new String[] { "ID" });
pstmt.setString(1, member.getEmail());
pstmt.setString(2, member.getPassword());
pstmt.setString(3, member.getName());
pstmt.setTimestamp(4, new Timestamp(member.getRegisterDate().getTime()));
pstmt.setString(5, member.getPhoto());
return pstmt;
}
}, keyHolder);
Number keyValue = keyHolder.getKey();
member.setId(keyValue.longValue());
}
use of org.springframework.jdbc.core.PreparedStatementCreator in project training_portal by training-portal.
the class QuizDaoJdbc method addQuiz.
@Transactional
@Override
public Long addQuiz(Quiz quiz) {
KeyHolder keyHolder = new GeneratedKeyHolder();
template.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement stmt = con.prepareStatement(ADD_QUIZ, new String[] { "quiz_id" });
stmt.setString(1, quiz.getName());
stmt.setString(2, quiz.getDescription());
stmt.setString(3, quiz.getExplanation());
stmt.setDate(4, Date.valueOf(quiz.getCreationDate()));
stmt.setTime(5, quiz.getPassingTime() == null ? null : Time.valueOf(LocalTime.MIDNIGHT.plus(quiz.getPassingTime())));
stmt.setLong(6, quiz.getAuthorId());
stmt.setString(7, quiz.getTeacherQuizStatus().getTeacherQuizStatus());
return stmt;
}
}, keyHolder);
long quizId = keyHolder.getKey().longValue();
quiz.setQuizId(quizId);
logger.info("Quiz added: " + quiz);
return quizId;
}
use of org.springframework.jdbc.core.PreparedStatementCreator in project training_portal by training-portal.
the class AnswerSimpleDaoJdbc method addAnswerSimple.
@Transactional
@Override
public Long addAnswerSimple(AnswerSimple answerSimple) {
KeyHolder keyHolder = new GeneratedKeyHolder();
template.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement stmt = con.prepareStatement(ADD_ANSWER_SIMPLE, new String[] { "answer_simple_id" });
stmt.setLong(1, answerSimple.getQuestionId());
stmt.setString(2, answerSimple.getBody());
stmt.setBoolean(3, answerSimple.isCorrect());
return stmt;
}
}, keyHolder);
long answerSimpleId = keyHolder.getKey().longValue();
answerSimple.setAnswerSimpleId(answerSimpleId);
logger.info("Added answerSimple: " + answerSimple);
return answerSimpleId;
}
Aggregations