我正在使用连接类进行连接。但我想使用xml文件中的连接。
connection.java
public class connection {
public SimpleDriverDataSource getConnection( SimpleDriverDataSource dataSource) throws ClassNotFoundException {
dataSource.setDriverClass(org.postgresql.Driver.class);
dataSource.setUrl("jdbc:postgresql://localhost:5432/springdb");
dataSource.setUsername("postgres");
dataSource.setPassword("postgres");
return dataSource;
}
}
controller.java
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource = new dbconnection.connection().getConnection(dataSource);
JdbcTemplate jt = new JdbcTemplate(dataSource);
String sql = "SELECT * FROM user_info";
srs = jt.queryForRowSet(sql);
*我不想使用connection.java ..........我想用这个............. *
的applicationContext.xml
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.org.postgresql.Driver.class}"
p:url="${jdbc.jdbc:postgresql://localhost:5432/springdb}"
p:username="${jdbc.postgres}"
p:password="${jdbc.postgres}" />