本文整理匯總了Java中org.h2.jdbcx.JdbcDataSource.setURL方法的典型用法代碼示例。如果您正苦於以下問題:Java JdbcDataSource.setURL方法的具體用法?Java JdbcDataSource.setURL怎麽用?Java JdbcDataSource.setURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.h2.jdbcx.JdbcDataSource
的用法示例。
在下文中一共展示了JdbcDataSource.setURL方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initDb
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
@BeforeClass
public static void initDb() throws SQLException {
ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:estest;DB_CLOSE_DELAY=-1;MVCC=true");
ds.setUser("sa");
try (Connection con = ds.getConnection()) {
executeSql(
con,
"create table event (ID varchar, VERSION int, TIMESTAMP timestamp, TYPE varchar, PAYLOAD_VERSION int, PAYLOAD clob, primary key (ID, VERSION))",
" create table version (ID varchar, VERSION int)",
" create table snapshot(ID varchar primary key, VERSION int, TIMESTAMP timestamp, PAYLOAD_VERSION int, PAYLOAD clob)",
// we will not use primary key check to escalate optimistic lock exception in very last step
"create table event_collision (ID varchar, VERSION int, TIMESTAMP timestamp, TYPE varchar, PAYLOAD_VERSION int, PAYLOAD clob)");
}
template = new JdbcTemplate(ds);
}
示例2: before
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
@Before
public void before() {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
DBI dbi = new DBI(ds);
this.jsondb = new SqlJsonDB(dbi, null,
Arrays.asList(new Index("/pair", "key"))
);
try {
this.jsondb.dropTables();
} catch (Exception e) {
}
this.jsondb.createTables();
}
示例3: builderWithDataSource
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
@Test
public void builderWithDataSource() throws Exception {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:SqlAgentTest");
SqlConfig config = UroboroSQL.builder(ds).build();
try (SqlAgent agent = config.agent()) {
String[] sqls = new String(Files.readAllBytes(Paths.get("src/test/resources/sql/ddl/create_tables.sql")),
StandardCharsets.UTF_8).split(";");
for (String sql : sqls) {
if (StringUtils.isNotBlank(sql)) {
agent.updateWith(sql.trim()).count();
}
}
insert(agent, Paths.get("src/test/resources/data/setup", "testExecuteQuery.ltsv"));
agent.rollback();
}
assertEquals(new H2Dialect().getName(), config.getDialect().getName());
}
示例4: testMixedXaNormal
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
private void testMixedXaNormal() throws Exception {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test");
ds.setUser("sa");
ds.setPassword("");
XAConnection xa = ds.getXAConnection();
Connection c = xa.getConnection();
assertTrue(c.getAutoCommit());
MyXid xid = new MyXid();
XAResource res = xa.getXAResource();
res.start(xid, XAResource.TMNOFLAGS);
assertTrue(!c.getAutoCommit());
res.end(xid, XAResource.TMSUCCESS);
res.commit(xid, true);
assertTrue(c.getAutoCommit());
res.start(xid, XAResource.TMNOFLAGS);
assertTrue(!c.getAutoCommit());
res.end(xid, XAResource.TMFAIL);
res.rollback(xid);
assertTrue(c.getAutoCommit());
c.close();
xa.close();
}
示例5: testDataSource
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
private void testDataSource() throws SQLException {
deleteDb("dataSource");
JdbcDataSource ds = new JdbcDataSource();
PrintWriter p = new PrintWriter(new StringWriter());
ds.setLogWriter(p);
assertTrue(p == ds.getLogWriter());
ds.setURL(getURL("dataSource", true));
ds.setUser(getUser());
ds.setPassword(getPassword());
Connection conn;
conn = ds.getConnection();
Statement stat;
stat = conn.createStatement();
stat.execute("SELECT * FROM DUAL");
conn.close();
conn = ds.getConnection(getUser(), getPassword());
stat = conn.createStatement();
stat.execute("SELECT * FROM DUAL");
}
示例6: DLNAMediaDatabase
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
public DLNAMediaDatabase(String name) {
dbName = name;
File profileFolder = new File(configuration.getProfileFolder());
dbDir = new File(profileFolder.isDirectory() ? profileFolder : null, "database").getAbsolutePath();
boolean logDB = configuration.getDatabaseLogging();
url = Constants.START_URL + dbDir + File.separator + dbName + (logDB ? ";TRACE_LEVEL_FILE=4" : "");
LOGGER.debug("Using database URL: {}", url);
LOGGER.info("Using database located at: \"{}\"", dbDir);
if (logDB) {
LOGGER.info("Database logging is enabled");
} else if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Database logging is disabled");
}
try {
Class.forName("org.h2.Driver");
} catch (ClassNotFoundException e) {
LOGGER.error(null, e);
}
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(url);
ds.setUser("sa");
ds.setPassword("");
cp = JdbcConnectionPool.create(ds);
}
示例7: configs
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
@Parameterized.Parameters
public static Collection<Object[]> configs() {
EmbeddedDataSource derbyDs = new EmbeddedDataSource();
derbyDs.setDatabaseName("test");
derbyDs.setCreateDatabase("create");
JdbcDataSource h2Ds = new JdbcDataSource();
h2Ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
// Tests on postgres disabled
// PGPoolingDataSource postgresDs = new PGPoolingDataSource();
// postgresDs.setServerName("localhost");
// postgresDs.setDatabaseName("syndesis");
// postgresDs.setUser("postgres");
// postgresDs.setPassword("password");
return Arrays.asList(new Object[][]{
{derbyDs},
// {postgresDs},
{h2Ds}
});
}
示例8: createDatabase
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
/**
* To create certificate management database.
*
* @return Datasource.
* @throws SQLException SQL Exception.
*/
private DataSource createDatabase() throws SQLException {
URL resourceURL = ClassLoader.getSystemResource("sql-scripts" + File.separator + "h2.sql");
JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:mem:cert;DB_CLOSE_DELAY=-1");
dataSource.setUser("sa");
dataSource.setPassword("sa");
final String LOAD_DATA_QUERY = "RUNSCRIPT FROM '" + resourceURL.getPath() + "'";
Connection conn = null;
Statement statement = null;
try {
conn = dataSource.getConnection();
statement = conn.createStatement();
statement.execute(LOAD_DATA_QUERY);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {}
}
if (statement != null) {
statement.close();
}
}
return dataSource;
}
示例9: getH2Connection
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
private static Connection getH2Connection() {
try {
String url = "jdbc:h2:./h2db";
String name = "tully";
String pass = "tully";
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(url);
ds.setUser(name);
ds.setPassword(pass);
Connection connection = DriverManager.getConnection(url, name, pass);
return connection;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
示例10: before
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
@Override
public void before() throws Throwable {
// Set up JMS from super
super.before();
log.info("+++ BEFORE on JUnit Rule '" + id(Rule_MatsWithDb.class) + "', H2 database:");
log.info("Setting up H2 database using DB URL [" + H2_DATABASE_URL + "], dropping all objects.");
// Set up H2 Database
_dataSource = new JdbcDataSource();
_dataSource.setURL(H2_DATABASE_URL);
try {
try (Connection con = _dataSource.getConnection();
Statement stmt = con.createStatement();) {
stmt.execute("DROP ALL OBJECTS DELETE FILES");
}
}
catch (SQLException e) {
throw new RuntimeException("Got problems running 'DROP ALL OBJECTS DELETE FILES'.", e);
}
log.info("--- BEFORE done! JUnit Rule '" + id(Rule_MatsWithDb.class) + "', H2 database.");
}
示例11: getH2Connection
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
public static Connection getH2Connection() {
try {
String url = "jdbc:h2:./h2db";
String name = "tully";
String pass = "tully";
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(url);
ds.setUser(name);
ds.setPassword(pass);
Connection connection = DriverManager.getConnection(url, name, pass);
return connection;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
示例12: beforeClass
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
@BeforeClass
public static void beforeClass() throws Exception {
namingMixIn = new NamingMixIn();
namingMixIn.initialize();
connection = DriverManager.getConnection("jdbc:h2:mem:events-jpa-quickstart", "sa", "sa");
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:events-jpa-quickstart");
ds.setUser("sa");
ds.setPassword("sa");
InitialContext initialContext = new InitialContext();
bind(initialContext, System.getProperty("jpa.persistence.datasource.name"), ds);
}
示例13: startUp
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
@BeforeClass
public static void startUp() throws Exception {
dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:mem:test");
dataSource.setUser("sa");
dataSource.setPassword("sa");
connection = dataSource.getConnection();
String createStatement = "CREATE TABLE greetings ("
+ "id INT PRIMARY KEY AUTO_INCREMENT, "
+ "receiver VARCHAR(255), "
+ "sender VARCHAR(255) "
+ ");";
connection.createStatement().executeUpdate("DROP TABLE IF EXISTS greetings");
connection.createStatement().executeUpdate(createStatement);
namingMixIn = new NamingMixIn();
namingMixIn.initialize();
bindDataSource(namingMixIn.getInitialContext(), "java:jboss/myDS", dataSource);
}
示例14: testGetConnection
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
@Test
public void testGetConnection() throws Exception {
JdbcDataSource h2DataSource = new JdbcDataSource();
h2DataSource.setURL("jdbc:h2:mem:");
DataSource sniffyDataSource = new SniffyDataSource(h2DataSource);
try (Connection connection = sniffyDataSource.getConnection()) {
assertNotNull(connection);
assertTrue(Proxy.isProxyClass(connection.getClass()));
try (Spy spy = Sniffy.expect(SqlQueries.exactQueries(1));
Statement statement = connection.createStatement()) {
statement.execute("SELECT 1 FROM DUAL");
statement.getResultSet().next();
}
}
}
示例15: initDataSource
import org.h2.jdbcx.JdbcDataSource; //導入方法依賴的package包/類
private static DataSource initDataSource() {
JdbcDataSource dataSource = new JdbcDataSource();
String dbUrl = DatabaseCreator.nextUrl();
dataSource.setURL(dbUrl);
String jndiName = "jdbc/RxDS";
try {
Context context = new InitialContext();
context.rebind(jndiName, dataSource);
} catch (NamingException e) {
throw new RuntimeException(e);
}
return dataSource;
}