/** * @param ds the data source to keep the mapping information */ public void setDataSource(DataSource ds) { this.ds = ds; jdbc = new SimpleJdbcTemplate(this.ds); }
private SimpleJdbcTemplate simpleJdbcTemplate; protected SimpleJdbcTemplate getSimpleJdbcTemplate() { return simpleJdbcTemplate; } @Autowired public void setDataSource(DataSource dataSource) { this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); }
package com.stackoverflow.q4684102; import javax.jdbc.DataSource; import org.springframework.jdbc.core.simple.*; public class Example implements YourDaoInterface { private SimpleJdbcOperations jdbc; public void setDataSource(DataSource ds) { jdbc = new SimpleJdbcTemplate(ds); } // your DAO methods here }
public SpringSqlPlusDao(DataSource dataSource){ this.dataSource = dataSource; jdbcTemplate = new SimpleJdbcTemplate(dataSource); }
public Shutdown(DataSource ds) { this(); this.jdbc = new org.springframework.jdbc.core.simple.SimpleJdbcTemplate(ds); }
/** * @param ds The DataSource to use for queries * @param queryTemplate Template to use for SQL query generation. Use {0} as the placeholder for where the generated portion of the WHERE clause should be inserted. */ public AbstractJdbcPersonAttributeDao(DataSource ds, String queryTemplate) { Validate.notNull(ds, "DataSource can not be null"); Validate.notNull(queryTemplate, "queryTemplate can not be null"); this.simpleJdbcTemplate = new SimpleJdbcTemplate(ds); this.queryTemplate = queryTemplate; }
/** * @param ds The DataSource to use for queries * @param sql The SQL to execute */ public AbstractJdbcPersonAttributeDao(DataSource ds, String sql) { Validate.notNull(ds, "DataSource can not be null"); Validate.notNull(sql, "sql can not be null"); this.simpleJdbcTemplate = new SimpleJdbcTemplate(ds); this.sql = sql; }
SimpleJdbcTemplate db; DataSource dataSource = new SingleConnectionDataSource(System.getProperty( "lingcog.db.connectstring"), System.getProperty("lingcog.db.username"), System.getProperty("lingcog.db.password"), false); db = new SimpleJdbcTemplate(dataSource);
/** * Create a SimpleJdbcTemplate based on the configured JdbcTemplate. */ @Override protected void initTemplateConfig() { this.simpleJdbcTemplate = new SimpleJdbcTemplate(getJdbcTemplate()); }
// First create a DataSource corresponding to a single connection. // Your production application could potentially use a connection pool. // true == suppress close of underlying connection when close() is called. DataSource ds = new SingleConnectionDataSource("com.MyDriver", "Database URL", "user", "password", true); // Now create a SimpleJdbcTemplate passing in the DataSource. This provides many // useful utility methods. SimpleJdbcTemplate tmpl = new SimpleJdbcTemplate(ds);
public Collection<Integer> listConversationsSince(int id) throws DataAccessException { MapSqlParameterSource params = new MapSqlParameterSource(); try { params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.query(SELECT_CONVERSATIONS, ID_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return Collections.emptyList(); } }
public int getMessageContentSize(int id) throws DataAccessException { try { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForInt(SELECT_CONTENT_SIZE, params); } catch (EmptyResultDataAccessException erdae) { return -1; } }
public byte[] loadMessageContent(int id) throws DataAccessException { try { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForObject(SELECT_CONTENT, CONTENT_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return null; } }
public RequestHeader loadRequestHeader(int id) throws DataAccessException { MapSqlParameterSource params = new MapSqlParameterSource(); try { params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForObject(SELECT_REQUEST, REQUEST_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return null; } }
public int getMessageContentId(int headerId) throws DataAccessException { try { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, headerId, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForInt(SELECT_CONTENT_ID, params); } catch (EmptyResultDataAccessException erdae) { return -1; } }
public Conversation getConversation(int id) throws DataAccessException { try { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForObject(SELECT_SUMMARY, CONVERSATION_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return null; } }
public MutableResponseHeader loadResponseHeader(int id) throws DataAccessException { try { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(ID, id, Types.INTEGER); SimpleJdbcTemplate template = new SimpleJdbcTemplate( getNamedParameterJdbcTemplate()); return template.queryForObject(SELECT_RESPONSE, RESPONSE_MAPPER, params); } catch (EmptyResultDataAccessException erdae) { return null; } }
@Before public void before() throws SQLException { SimpleJdbcTestUtils.executeSqlScript( new SimpleJdbcTemplate(txContext.getJdbcTemplate()), new ClassPathResource("test.sql"), true); txContext.commitTransactionAndBeginNewOne(); firstExampleEntity = new ExampleEntity(0, "nameInBefore"); txContext.getJdbcTemplate().execute("INSERT INTO EXAMPLEENTITIES (name) VALUES ('" + firstExampleEntity.getName() + "')"); firstExampleEntity.setId(txContext.getJdbcTemplate().queryForInt("SELECT LAST_INSERT_ID()")); }
@Before public void before() throws SQLException { SimpleJdbcTestUtils.executeSqlScript( new SimpleJdbcTemplate(txContext.getSqlMapClientTemplate().getDataSource()), new ClassPathResource("test.sql"), true); txContext.commitTransactionAndBeginNewOne(); firstExampleEntity = new ExampleEntity(0, "nameInBefore"); txContext.getSqlMapClientTemplate().insert("insert", firstExampleEntity); }
@Autowired(required = true) public void initialize(final DataSource dataSource) { this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); this.bookInsert = new SimpleJdbcInsert(dataSource).withTableName("books") .usingGeneratedKeyColumns("id"); }