Giriş
Şu satırı dahil ederiz.
XML
Şöyle yaparız.
Örnek
Şöyle yaparız.
Şöyle yaparızz
Şöyle yaparız.
Şöyle yaparız.
Şöyle yaparız.
Şöyle yaparız.
Şu satırı dahil ederiz.
import org.springframework.jdbc.datasource.DriverManagerDataSource;Bu sınıf örneğin org.springframework.orm.hibernate5.LocalSessionFactoryBean nesnesine geçilir.This class is not an actual connection pool; it does not actually pool Connections. It just serves as simple replacement for a full-blown connection pool, implementing the same standard interface, but creating new Connections on every call.If you need a "real" connection pool outside of a J2EE container, consider Apache's Jakarta Commons DBCP or C3P0. Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full connection pool beans, supporting the same basic properties as this class plus specific settings (such as minimal/maximal pool size etc).
XML
Şöyle yaparız.
<bean id="postgresDataSource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource"
  p:driverClassName="org.postgresql.Driver"
  p:url="jdbc:postgresql://localhost:5432/test?createDatabaseIfNotExist=true"
  p:username="test"
  p:password="test"/>
<bean id="sqlDataSource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource"
  p:driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
  p:url="jdbc:sqlserver://localhost:1433;databaseName=test"
  p:username="test"
  p:password="test"/>Örnek
Şöyle yaparız.
DriverManagerDataSource dataSource = new DriverManagerDataSource();Şöyle yaparızz
@Bean(name = "dataSource")
public DataSource creatDataSource() {
  DriverManagerDataSource ds = new DriverManagerDataSource();
  ds.setDriverClassName(driverClassName);
  ds.setUrl(url);
  ds.setUsername(username);
  ds.setPassword(password);
  return ds;
}Şöyle yaparız.
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");Şöyle yaparız.
dataSource.setUrl("jdbc:mysql://localhost:3306/rshared?autoReconnect=true");Şöyle yaparız.
dataSource.setUsername("root");Şöyle yaparız.
dataSource.setPassword("root"); 
Hiç yorum yok:
Yorum Gönder