本文整理汇总了Java中org.springframework.jdbc.datasource.SimpleDriverDataSource类的典型用法代码示例。如果您正苦于以下问题:Java SimpleDriverDataSource类的具体用法?Java SimpleDriverDataSource怎么用?Java SimpleDriverDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleDriverDataSource类属于org.springframework.jdbc.datasource包,在下文中一共展示了SimpleDriverDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeJiraDataBaseForSla
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
/**
* Initialize data base with 'MDA' JIRA project.
*/
@BeforeClass
public static void initializeJiraDataBaseForSla() throws SQLException {
final DataSource datasource = new SimpleDriverDataSource(new JDBCDriver(), "jdbc:hsqldb:mem:dataSource", null, null);
final Connection connection = datasource.getConnection();
try {
ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/sla/jira-create.sql"), StandardCharsets.UTF_8));
ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/sla/jira.sql"), StandardCharsets.UTF_8));
} finally {
connection.close();
}
}
示例2: SqlServerFlywayTestMigrationStrategy
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
public SqlServerFlywayTestMigrationStrategy(DataSourceProperties dataSourceProps) {
Pattern jdbcBaseUrlWithDbNamePattern = Pattern.compile(DB_URL_PATTERN);
Matcher matcher = jdbcBaseUrlWithDbNamePattern.matcher(dataSourceProps.getUrl());
if(!matcher.matches()) {
throw new IllegalArgumentException(dataSourceProps.getUrl() + " does not match " + DB_URL_PATTERN);
}
String jdbcBaseUrl = matcher.group("jdbcBaseUrl");
String databaseName = matcher.group("databaseName");
databaseExistsQuery = String.format("SELECT count(*) FROM sys.databases WHERE name='%s'", databaseName);
createDatabaseQuery = String.format("CREATE DATABASE %s", databaseName);
this.template = new JdbcTemplate(new SimpleDriverDataSource(
getDriver(jdbcBaseUrl),
jdbcBaseUrl,
dataSourceProps.getUsername(),
dataSourceProps.getPassword()));
}
开发者ID:infobip,项目名称:infobip-spring-data-jpa-querydsl,代码行数:19,代码来源:SqlServerFlywayTestMigrationStrategy.java
示例3: getConn
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
private Connection getConn(String url, String userName, String password) throws SQLException {
Driver driver = null;
if (url.contains("mysql")) {
driver = new com.mysql.jdbc.Driver();
} else if (url.contains("postgresql")) {
driver = new org.postgresql.Driver();
} else if (url.contains("sqlserver")) {
driver = new com.microsoft.sqlserver.jdbc.SQLServerDriver();
} else if (url.contains("oracle")) {
driver = new oracle.jdbc.OracleDriver();
} else {
throw new RuntimeException("不支持此类型数据库");
}
DataSource dataSource = new SimpleDriverDataSource(driver, url, userName, password);
try {
return dataSource.getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例4: initializeJiraDataBase
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
/**
* Initialize data base with 'MDA' JIRA project.
*/
@BeforeClass
public static void initializeJiraDataBase() throws SQLException {
datasource = new SimpleDriverDataSource(new JDBCDriver(), "jdbc:hsqldb:mem:dataSource", null, null);
final Connection connection = datasource.getConnection();
final JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
try {
ScriptUtils.executeSqlScript(connection,
new EncodedResource(new ClassPathResource("sql/base-1/jira-create.sql"), StandardCharsets.UTF_8));
ScriptUtils.executeSqlScript(connection,
new EncodedResource(new ClassPathResource("sql/base-1/jira.sql"), StandardCharsets.UTF_8));
jdbcTemplate.queryForList("SELECT * FROM pluginversion WHERE ID = 10075");
} finally {
connection.close();
}
}
示例5: initializeJiraDataBaseForImport
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
/**
* Initialize data base with 'MDA' JIRA project.
*/
@BeforeClass
public static void initializeJiraDataBaseForImport() throws SQLException {
datasource = new SimpleDriverDataSource(new JDBCDriver(), "jdbc:hsqldb:mem:dataSource", null, null);
final Connection connection = datasource.getConnection();
try {
ScriptUtils.executeSqlScript(connection,
new EncodedResource(new ClassPathResource("sql/base-1/jira-create.sql"), StandardCharsets.UTF_8));
ScriptUtils.executeSqlScript(connection,
new EncodedResource(new ClassPathResource("sql/base-2/jira-create.sql"), StandardCharsets.UTF_8));
ScriptUtils.executeSqlScript(connection,
new EncodedResource(new ClassPathResource("sql/upload/jira-create.sql"), StandardCharsets.UTF_8));
ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/base-1/jira.sql"), StandardCharsets.UTF_8));
ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/base-2/jira.sql"), StandardCharsets.UTF_8));
ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/upload/jira.sql"), StandardCharsets.UTF_8));
} finally {
connection.close();
}
}
示例6: shutdownDatabase
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
/**
* Hook to shutdown the embedded database. Subclasses may call this method
* to force shutdown.
* <p>After calling, {@link #getDataSource()} returns {@code null}.
* <p>Does nothing if no embedded database has been initialized.
*/
protected void shutdownDatabase() {
if (this.dataSource != null) {
if (logger.isInfoEnabled()) {
if (this.dataSource instanceof SimpleDriverDataSource) {
logger.info(String.format("Shutting down embedded database: url='%s'",
((SimpleDriverDataSource) this.dataSource).getUrl()));
}
else {
logger.info(String.format("Shutting down embedded database '%s'", this.databaseName));
}
}
this.databaseConfigurer.shutdown(this.dataSource, this.databaseName);
this.dataSource = null;
}
}
示例7: sqlInsertComment
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
public void sqlInsertComment() {
String comment = "something"; // TODO: 17.02.2016 задание строки юзером
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(com.mysql.jdbc.Driver.class);
dataSource.setUsername("root");
dataSource.setUrl("jdbc:mysql://localhost/wlogs");
dataSource.setPassword("root");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
System.out.println("checking connection...");
try {
System.out.println("getting current statistic table...");
createTable();
System.out.println("Insert comment");
jdbcTemplate.update("INSERT INTO statistic (comment) VALUE (?)", comment);
} catch (Exception e) {
sqlCheck = "Have error " + e;
System.err.println(sqlCheck);
}
}
示例8: sqlInsert
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
public void sqlInsert() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(com.mysql.jdbc.Driver.class);
dataSource.setUsername("root");
dataSource.setUrl("jdbc:mysql://localhost/webstore");
dataSource.setPassword("root");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
System.out.println("try to update db...");
try {
System.out.println("Creating tables");
/*jdbcTemplate.execute("DROP TABLE IF EXISTS products");
jdbcTemplate.execute("create table products(ID INT NOT NULL,"
+ " pName MEDIUMTEXT NOT NULL, description LONGTEXT)");*/
// jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(1, 'apple', 'red')");
// jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(2, 'banan', 'yellow')");
// jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(3, 'bread', null)");
jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(4, 'milk', 'natural')");
jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(5, 'becon', null)");
jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(6, 'bread', 'black')");
sqlCheck = "db updated";
} catch (Exception e) {
sqlCheck = "Have error: " + e;
System.err.println(sqlCheck);
}
}
示例9: sqlInsert
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
public void sqlInsert() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(com.mysql.jdbc.Driver.class);
dataSource.setUsername("root");
dataSource.setUrl("jdbc:mysql://localhost/webstore");
dataSource.setPassword("root");
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
System.out.println("try to update db...");
try {
System.out.println("Creating tables");
jdbcTemplate.execute("DROP TABLE IF EXISTS products");
jdbcTemplate.execute("create table products(ID INT NOT NULL,"
+ " pname MEDIUMTEXT NOT NULL, description MEDIUMTEXT NOT NULL)");
jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(7, 'milk', 'cow')");
jdbcTemplate.update("INSERT INTO products(ID, pName, description) VALUES(8, 'bread', 'grey')");
sqlCheck = "db updated";
} catch (Exception e) {
sqlCheck = "Have error: " + e;
System.err.println(sqlCheck);
}
}
示例10: main
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
public static void main(String[] args) {
ExperimentDAO source = null;
ExperimentDAO target = null;
try {
source = new ExperimentDAOImpl(
new SimpleDriverDataSource(new org.hsqldb.jdbc.JDBCDriver(), "jdbc:hsqldb:file:" + SOURCE_DB_PATH));
source.initialize();
target = new ExperimentDAOImpl(
new SimpleDriverDataSource(new org.hsqldb.jdbc.JDBCDriver(), "jdbc:hsqldb:file:" + TARGET_DB_PATH));
target.initialize();
performMigration(source, target);
} finally {
IOUtils.closeQuietly(source);
IOUtils.closeQuietly(target);
}
}
示例11: buildJdbcHelper
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
@Override
protected AbstractJdbcHelper buildJdbcHelper() throws SQLException {
String hostAndPort = System.getProperty("mysql.hostAndPort", "localhost:3306");
String user = System.getProperty("mysql.user", "travis");
String password = System.getProperty("mysql.pwd", "");
String db = System.getProperty("mysql.db", "test");
String url = "jdbc:mysql://" + hostAndPort + "/" + db
+ "?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
DataSource ds = new SimpleDriverDataSource(DriverManager.getDriver(url), url, user,
password);
DdthJdbcHelper jdbcHelper = new DdthJdbcHelper();
jdbcHelper.setDataSource(ds);
jdbcHelper.init();
return jdbcHelper;
}
示例12: buildJdbcHelper
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
@Override
protected AbstractJdbcHelper buildJdbcHelper() throws SQLException {
String hostAndPort = System.getProperty("mysql.hostAndPort", "localhost:3306");
String user = System.getProperty("mysql.user", "travis");
String password = System.getProperty("mysql.pwd", "");
String db = System.getProperty("mysql.db", "test");
String url = "jdbc:mysql://" + hostAndPort + "/" + db
+ "?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
DataSource ds = new SimpleDriverDataSource(DriverManager.getDriver(url), url, user,
password);
JdbcTemplateJdbcHelper jdbcHelper = new JdbcTemplateJdbcHelper();
jdbcHelper.setDataSource(ds);
jdbcHelper.init();
return jdbcHelper;
}
示例13: buildUserDao
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
@Override
protected UserBoJdbcDao buildUserDao() throws SQLException {
String hostAndPort = System.getProperty("mysql.hostAndPort", "localhost:3306");
String user = System.getProperty("mysql.user", "travis");
String password = System.getProperty("mysql.pwd", "");
String db = System.getProperty("mysql.db", "test");
String url = "jdbc:mysql://" + hostAndPort + "/" + db
+ "?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
DataSource ds = new SimpleDriverDataSource(DriverManager.getDriver(url), url, user,
password);
JdbcTemplateJdbcHelper jdbcHelper = new JdbcTemplateJdbcHelper();
jdbcHelper.setDataSource(ds);
jdbcHelper.init();
GenericUserBoRowMapper rowMapper = new GenericUserBoRowMapper();
UserBoJdbcDao userDao = new UserBoJdbcDao();
userDao.setTableName("tbl_user_gjd").setRowMapper(rowMapper).setJdbcHelper(jdbcHelper);
userDao.init();
return userDao;
}
示例14: buildUserDao
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
@Override
protected UserBoJdbcDao buildUserDao() throws SQLException {
String hostAndPort = System.getProperty("mysql.hostAndPort", "localhost:3306");
String user = System.getProperty("mysql.user", "travis");
String password = System.getProperty("mysql.pwd", "");
String db = System.getProperty("mysql.db", "test");
String url = "jdbc:mysql://" + hostAndPort + "/" + db
+ "?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false";
DataSource ds = new SimpleDriverDataSource(DriverManager.getDriver(url), url, user,
password);
DdthJdbcHelper jdbcHelper = new DdthJdbcHelper();
jdbcHelper.setDataSource(ds);
jdbcHelper.init();
GenericUserBoRowMapper rowMapper = new GenericUserBoRowMapper();
UserBoJdbcDao userDao = new UserBoJdbcDao();
userDao.setTableName("tbl_user_gjd").setRowMapper(rowMapper).setJdbcHelper(jdbcHelper);
userDao.init();
return userDao;
}
示例15: buildSimpleDataSource
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DataSource buildSimpleDataSource(DataSourceConfiguration cfg) {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
Class<? extends Driver> driverClass;
try {
driverClass = (Class<? extends Driver>) Class.forName(cfg.getDriverClassName());
} catch (ClassNotFoundException e) {
throw new NetxiliaResourceException("Cannot find class driver:" + cfg.getDriverClassName());
}
dataSource.setDriverClass(driverClass);
dataSource.setUrl(cfg.getUrl().replace(NETXILIA_HOME_VAR, path));
dataSource.setUsername(cfg.getUsername());
dataSource.setPassword(cfg.getPassword());
return dataSource;
}