use of org.springframework.jdbc.core.simple.SimpleJdbcTemplate in project flyway by flyway.
the class Main method main.
/**
* Runs the sample.
*
* @param args None supported.
*/
public static void main(String[] args) throws Exception {
Flyway flyway = new Flyway();
flyway.setDataSource("jdbc:hsqldb:file:db/flyway_sample;shutdown=true", "SA", "");
flyway.setLocations("db/migration", "org.flywaydb.sample.migration");
flyway.setResolvers(new SampleResolver());
flyway.migrate();
SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(flyway.getDataSource());
List<Map<String, Object>> results = jdbcTemplate.queryForList("select name from test_user");
for (Map<String, Object> result : results) {
System.out.println("Name: " + result.get("NAME"));
}
}
use of org.springframework.jdbc.core.simple.SimpleJdbcTemplate in project JavaForFun by gumartinm.
the class RawSpringJDBCWithPoolExample method main.
public static void main(final String[] args) throws PropertyVetoException {
// Just for fun, programmatic configuration.
final DataSource dataSource = getDataSource();
final Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("AD_ID", 1);
// 3. Using Spring JdbcTemplate
final JdbcOperations jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.execute("SELECT * FROM AD");
// 4. Using SimpleJdbcTemplate
final SimpleJdbcOperations simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
final int deprecatedResult = simpleJdbcTemplate.queryForInt("SELECT * FROM AD", parameters);
logger.info("Deprecated result: " + deprecatedResult);
// 5. Using NamedParameterJdbcTemplate
final NamedParameterJdbcOperations namedParameterJdbcOperations = new NamedParameterJdbcTemplate(dataSource);
final int namedResult = namedParameterJdbcOperations.queryForInt("SELECT * FROM AD", parameters);
logger.info("Named result: " + namedResult);
// 6. Using Spring SimpleJdbcInsert
final SimpleJdbcInsertOperations simpleJdbcInsert = new SimpleJdbcInsert(dataSource);
simpleJdbcInsert.withTableName("ad");
simpleJdbcInsert.execute(parameters);
// 7. Using Spring SimpleJdbcCall
final SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(dataSource);
// Now we close the whole pool :)
((ComboPooledDataSource) dataSource).close();
}
Aggregations