本文整理了Java中org.springframework.jdbc.core.JdbcTemplate.<init>()
方法的一些代码示例,展示了JdbcTemplate.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JdbcTemplate.<init>()
方法的具体详情如下:
包路径:org.springframework.jdbc.core.JdbcTemplate
类名称:JdbcTemplate
方法名:<init>
[英]Construct a new JdbcTemplate for bean usage.
Note: The DataSource has to be set before using the instance.
[中]为bean使用构造一个新的JdbcTemplate。
注意:在使用实例之前必须设置数据源。
代码示例来源:origin: spring-projects/spring-framework
/**
* Constructor to be used when initializing using a {@link DataSource}.
* @param dataSource the DataSource to be used
*/
protected AbstractJdbcInsert(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a JdbcTemplate for the given DataSource.
* Only invoked if populating the DAO with a DataSource reference!
* <p>Can be overridden in subclasses to provide a JdbcTemplate instance
* with different configuration, or a custom JdbcTemplate subclass.
* @param dataSource the JDBC DataSource to create a JdbcTemplate for
* @return the new JdbcTemplate instance
* @see #setDataSource
*/
protected JdbcTemplate createJdbcTemplate(DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Constructor to be used when initializing using a {@link DataSource}.
* @param dataSource the DataSource to be used
*/
protected AbstractJdbcCall(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the DataSource to use to obtain database connections.
* Will implicitly create a new JdbcTemplate with the given DataSource.
*/
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a new NamedParameterJdbcTemplate for the given {@link DataSource}.
* <p>Creates a classic Spring {@link org.springframework.jdbc.core.JdbcTemplate} and wraps it.
* @param dataSource the JDBC DataSource to access
*/
public NamedParameterJdbcTemplate(DataSource dataSource) {
Assert.notNull(dataSource, "DataSource must not be null");
this.classicJdbcTemplate = new JdbcTemplate(dataSource);
}
代码示例来源:origin: spring-projects/spring-framework
@Autowired
@Override
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
代码示例来源:origin: spring-projects/spring-framework
@Autowired
@Override
public void setDataSource(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testScriptNameWithPattern() throws Exception {
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-pattern-config.xml");
DataSource dataSource = context.getBean("dataSource", DataSource.class);
assertCorrectSetup(dataSource);
JdbcTemplate t = new JdbcTemplate(dataSource);
assertEquals("Dave", t.queryForObject("select name from T_TEST", String.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBatchUpdateWithEmptyMap() throws Exception {
@SuppressWarnings("unchecked")
final Map<String, Integer>[] ids = new Map[0];
namedParameterTemplate = new NamedParameterJdbcTemplate(new JdbcTemplate(dataSource, false));
int[] actualRowsAffected = namedParameterTemplate.batchUpdate(
"UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = :id", ids);
assertTrue("executed 0 updates", actualRowsAffected.length == 0);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBatchUpdateWithEmptyList() throws Exception {
final String sql = "UPDATE NOSUCHTABLE SET DATE_DISPATCHED = SYSDATE WHERE ID = ?";
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
int[] actualRowsAffected = template.batchUpdate(sql, Collections.emptyList());
assertTrue("executed 0 updates", actualRowsAffected.length == 0);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@Sql("data-add-dogbert.sql")
public void database1() {
assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@Transactional(transactionManager = "txMgr2")
@Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(dataSource = "dataSource2", transactionManager = "txMgr2"))
public void database2() {
assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@Transactional("txMgr1")
@Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionManager = "txMgr1"))
public void database1() {
assertInTransaction(true);
assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@Sql("data-add-dogbert.sql")
public void database1() {
assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(dataSource = "dataSource2", transactionManager = "txMgr2"))
public void database2() {
assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(transactionManager = "txMgr2"))
public void database2() {
assertInTransaction(false);
assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionManager = "txMgr1"))
public void database1() {
assertInTransaction(false);
assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testCouldNotGetConnectionForOperationOrExceptionTranslator() throws SQLException {
SQLException sqlException = new SQLException("foo", "07xxx");
this.dataSource = mock(DataSource.class);
given(this.dataSource.getConnection()).willThrow(sqlException);
JdbcTemplate template = new JdbcTemplate(this.dataSource, false);
RowCountCallbackHandler rcch = new RowCountCallbackHandler();
this.thrown.expect(CannotGetJdbcConnectionException.class);
this.thrown.expect(exceptionCause(sameInstance(sqlException)));
template.query("SELECT ID, FORENAME FROM CUSTMR WHERE ID < 3", rcch);
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setUp() {
db = new EmbeddedDatabaseBuilder().setType(getEmbeddedDatabaseType()).build();
jdbcTemplate = new JdbcTemplate(db);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testFactoryBeanLifecycle() throws Exception {
EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean();
ResourceDatabasePopulator populator = new ResourceDatabasePopulator(resource("db-schema.sql"),
resource("db-test-data.sql"));
bean.setDatabasePopulator(populator);
bean.afterPropertiesSet();
DataSource ds = bean.getObject();
JdbcTemplate template = new JdbcTemplate(ds);
assertEquals("Keith", template.queryForObject("select NAME from T_TEST", String.class));
bean.destroy();
}
内容来源于网络,如有侵权,请联系作者删除!