本文整理汇总了Java中org.springframework.jdbc.datasource.SimpleDriverDataSource.setDriverClass方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleDriverDataSource.setDriverClass方法的具体用法?Java SimpleDriverDataSource.setDriverClass怎么用?Java SimpleDriverDataSource.setDriverClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.jdbc.datasource.SimpleDriverDataSource
的用法示例。
在下文中一共展示了SimpleDriverDataSource.setDriverClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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;
}
示例5: createDataSource
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
private SimpleDriverDataSource createDataSource() {
SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
simpleDriverDataSource.setDriverClass(org.h2.Driver.class);
simpleDriverDataSource.setUrl("jdbc:h2:mem:prod;MODE=MySQL;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS \"public\"");
simpleDriverDataSource.setUsername("sa");
simpleDriverDataSource.setPassword("");
return simpleDriverDataSource;
}
示例6: createDataSource
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
private SimpleDriverDataSource createDataSource() {
SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
simpleDriverDataSource.setDriverClass(org.hsqldb.jdbcDriver.class);
simpleDriverDataSource.setUrl(environment.getProperty("marketplace.system-db"));
simpleDriverDataSource.setUsername("");
simpleDriverDataSource.setPassword("");
return simpleDriverDataSource;
}
示例7: dataSource
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
@Bean
public DataSource dataSource() {
SimpleDriverDataSource ds = new SimpleDriverDataSource();
ds.setDriverClass(org.h2.Driver.class);
// Connection settings
ds.setUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000");
ds.setUsername("sa");
return ds;
}
示例8: initConnection
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
public void initConnection() {
dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(com.mysql.jdbc.Driver.class);
dataSource.setUsername("root");
dataSource.setUrl("jdbc:mysql://localhost/webstore");
dataSource.setPassword("root");
jdbcTemplate = new JdbcTemplate(dataSource);
}
示例9: dataSource
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
/**
* 定义数据源
* @return
* @throws ClassNotFoundException
*/
@Bean
public DataSource dataSource() throws ClassNotFoundException {
SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
simpleDriverDataSource.setDriverClass((Class<? extends Driver>) Class.forName("org.h2.Driver"));
simpleDriverDataSource.setUrl("jdbc:h2:mem:aia-chapter7;DB_CLOSE_DELAY=1000");
simpleDriverDataSource.setUsername("sa");
simpleDriverDataSource.setPassword("");
return simpleDriverDataSource;
}
示例10: connectJdbcOnWithUrlAndDriverAndUsernameAndPassword
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
/**
* Registers a database to further execute SQL commands
*
* <p><code>
* | connect jdbc on | <i>database</i> | with url | <i>url</i> | and driver | <i>driver</i> | and username | <i>username</i> | and | <i>password</i> |
* </code></p>
* @param url
*/
@SuppressWarnings("unchecked")
public boolean connectJdbcOnWithUrlAndDriverAndUsernameAndPassword(String dataBaseId, String url, String driverClassName, String username, String password) throws ReflectiveOperationException {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUrl(url);
dataSource.setDriverClass((Class<Driver>) Class.forName(driverClassName));
dataSource.setUsername(username);
dataSource.setPassword(password);
this.templateMap.put(dataBaseId, new JdbcTemplate(dataSource));
return true;
}
示例11: createDataSource
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
private SimpleDriverDataSource createDataSource() {
SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
simpleDriverDataSource.setDriverClass(org.h2.Driver.class);
simpleDriverDataSource.setUrl("jdbc:h2:./target/database/example;AUTO_RECONNECT=TRUE");
simpleDriverDataSource.setUsername("");
simpleDriverDataSource.setPassword("");
return simpleDriverDataSource;
}
示例12: dataSource_plain
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
@Bean
public DataSource dataSource_plain() {
SimpleDriverDataSource ds =
new SimpleDriverDataSource();
ds.setDriverClass(null);
ds.setUrl("jdbc:oracle:thin:@<server>[:<1521>]:<database_name>");
ds.setUsername("");
ds.setPassword("");
return ds;
}
示例13: getDataSource
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
public DataSource getDataSource() throws FastLdrException {
String url = createUrl();
try {
Class<? extends Driver> driver = (Class<? extends Driver>) Class.forName("oracle.jdbc.OracleDriver");
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(driver);
dataSource.setUrl(url);
UserID userID = cmdArguments.getUserID();
dataSource.setUsername(userID.getUser());
dataSource.setPassword(userID.getPassword());
return dataSource;
} catch (ClassNotFoundException e) {
throw new FastLdrException(e);
}
}
示例14: getDataSource
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
public DataSource getDataSource() throws FastLdrException {
try {
Class<? extends Driver> driver = (Class<? extends Driver>) Class.forName(driverClassName);
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
} catch (ClassNotFoundException e) {
throw new FastLdrException(e);
}
}
示例15: createSchemaIfNeeded
import org.springframework.jdbc.datasource.SimpleDriverDataSource; //导入方法依赖的package包/类
public static void createSchemaIfNeeded(String dbType, String dbAddress, String dbName, String dbUser, String dbPassword, String dbSchema)
throws SQLException {
if (!DEFAULT_SCHEMA_NAME.equals(dbSchema)) {
SimpleDriverDataSource ds = new SimpleDriverDataSource();
ds.setDriverClass(Driver.class);
ds.setUrl(String.format("jdbc:%s://%s/%s", dbType, dbAddress, dbName));
try (Connection conn = ds.getConnection(dbUser, dbPassword)) {
try (Statement statement = conn.createStatement()) {
statement.execute("CREATE SCHEMA IF NOT EXISTS " + dbSchema);
}
}
}
}