Пример #1
0
 @Bean
 public DataSource dataSource() throws SQLException {
   SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
   dataSource.setDriver(new Driver());
   dataSource.setUrl("jdbc:mysql://localhost:3306/pensiondb");
   dataSource.setUsername("root");
   dataSource.setPassword("teresa");
   return dataSource;
 }
 @Bean
 public DataSource dataSource() {
   SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
   dataSource.setDriverClass(org.postgresql.Driver.class);
   dataSource.setUrl("jdbc:postgresql://localhost/Cinema");
   dataSource.setUsername("postgres");
   dataSource.setPassword("postgres");
   return dataSource;
 }
Пример #3
0
 private DataSource createSimpleDataSource() throws ClassNotFoundException {
   PropsUtil props = new PropsUtil("db.config.properties");
   SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
   dataSource.setDriverClass((Class<? extends Driver>) Class.forName(props.getString("driver")));
   dataSource.setUrl(props.getString("url"));
   dataSource.setUsername("");
   dataSource.setPassword("");
   return dataSource;
 }
Пример #4
0
 /** 构造数据源,仅构造一次. 连接参数从配置文件中读取,可指向本地的开发环境,也可以指向远程的测试服务器。 */
 protected static void buildDataSourceOnce() throws ClassNotFoundException {
   if (dataSource == null) {
     dataSource = new SimpleDriverDataSource();
     dataSource.setDriverClass(
         (Class<? extends Driver>) Class.forName(propertiesLoader.getProperty("jdbc.driver")));
     dataSource.setUrl(propertiesLoader.getProperty("jdbc.url"));
     dataSource.setUsername(propertiesLoader.getProperty("jdbc.username"));
     dataSource.setPassword(propertiesLoader.getProperty("jdbc.password"));
   }
 }
 @SuppressWarnings("unchecked")
 @Bean
 @Autowired
 DataSource getDataSource(Environment env)
     throws ClassNotFoundException, InstantiationException, IllegalAccessException {
   SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
   dataSource.setDriverClass(
       (Class<? extends java.sql.Driver>) Class.forName(env.getProperty("db.driver")));
   dataSource.setUrl(env.getProperty("db.url"));
   dataSource.setUsername(env.getProperty("db.username"));
   dataSource.setPassword(env.getProperty("db.password"));
   return dataSource;
 }
Пример #6
0
  @Bean(name = "dataSource")
  public DataSource dataSource() {
    /*BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/diagram");
    dataSource.setUsername("user");
    dataSource.setPassword("user");
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setTestOnBorrow(true);

    return dataSource;*/

    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    dataSource.setDriverClass(org.h2.Driver.class);
    dataSource.setUsername("sa");
    dataSource.setUrl(
        "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS diagram");
    dataSource.setPassword("");
    return dataSource;
  }