本文整理汇总了Java中org.h2.Driver类的典型用法代码示例。如果您正苦于以下问题:Java Driver类的具体用法?Java Driver怎么用?Java Driver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Driver类属于org.h2包,在下文中一共展示了Driver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initManagementDb
import org.h2.Driver; //导入依赖的package包/类
private void initManagementDb() throws SQLException {
Properties prop = new Properties();
prop.setProperty("user", "");
prop.setProperty("password", managementPassword);
// avoid using the driver manager
Connection conn = Driver.load().connect("jdbc:h2:" +
getManagementDbName(port), prop);
managementDb = conn;
Statement stat = null;
try {
stat = conn.createStatement();
stat.execute("CREATE ALIAS IF NOT EXISTS STOP_SERVER FOR \"" +
TcpServer.class.getName() + ".stopServer\"");
stat.execute("CREATE TABLE IF NOT EXISTS SESSIONS" +
"(ID INT PRIMARY KEY, URL VARCHAR, USER VARCHAR, " +
"CONNECTED TIMESTAMP)");
managementDbAdd = conn.prepareStatement(
"INSERT INTO SESSIONS VALUES(?, ?, ?, NOW())");
managementDbRemove = conn.prepareStatement(
"DELETE FROM SESSIONS WHERE ID=?");
} finally {
JdbcUtils.closeSilently(stat);
}
SERVERS.put(port, this);
}
示例2: getJdbcConnection
import org.h2.Driver; //导入依赖的package包/类
private JdbcConnection getJdbcConnection(String user, char[] password)
throws SQLException {
if (isDebugEnabled()) {
debugCode("getJdbcConnection("+quote(user)+", new char[0]);");
}
Properties info = new Properties();
info.setProperty("user", user);
info.put("password", password);
Connection conn = Driver.load().connect(url, info);
if (conn == null) {
throw new SQLException("No suitable driver found for " + url,
"08001", 8001);
} else if (!(conn instanceof JdbcConnection)) {
throw new SQLException(
"Connecting with old version is not supported: " + url,
"08001", 8001);
}
return (JdbcConnection) conn;
}
示例3: opened
import org.h2.Driver; //导入依赖的package包/类
@Override
public void opened() {
try {
// using DriverManager.getConnection could result in a deadlock
// when using the server mode, but within the same process
Properties prop = new Properties();
prop.setProperty("user", "sa");
prop.setProperty("password", "sa");
Connection conn = Driver.load().connect(databaseUrl, prop);
Statement stat = conn.createStatement();
stat.execute("create table if not exists test(id int)");
conn.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
示例4: testCalledForStatement
import org.h2.Driver; //导入依赖的package包/类
private void testCalledForStatement() throws SQLException {
Properties p = new Properties();
p.setProperty("user", "sa");
p.setProperty("password", "sa");
calledStatementStart = false;
calledStatementEnd = false;
calledStatementProgress = false;
p.put("DATABASE_EVENT_LISTENER", MyDatabaseEventListener.class.getName());
org.h2.Driver.load();
String url = "jdbc:h2:mem:databaseEventListener";
Connection conn = org.h2.Driver.load().connect(url, p);
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar)");
stat.execute("select * from test");
conn.close();
assertTrue(calledStatementStart);
assertTrue(calledStatementEnd);
assertTrue(calledStatementProgress);
}
示例5: beforeTest
import org.h2.Driver; //导入依赖的package包/类
/**
* This method is called before a complete set of tests is run. It deletes
* old database files in the test directory and trace files. It also starts
* a TCP server if the test uses remote connections.
*/
public void beforeTest() throws SQLException {
Driver.load();
FileUtils.deleteRecursive(TestBase.BASE_TEST_DIR, true);
DeleteDbFiles.execute(TestBase.BASE_TEST_DIR, null, true);
FileUtils.deleteRecursive("trace.db", false);
if (networked) {
String[] args = ssl ? new String[] { "-tcpSSL", "-tcpPort", "9192" }
: new String[] { "-tcpPort", "9192" };
server = Server.createTcpServer(args);
try {
server.start();
} catch (SQLException e) {
System.out.println("FAIL: can not start server (may already be running)");
server = null;
}
}
}
示例6: configure
import org.h2.Driver; //导入依赖的package包/类
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(
new PersistTestModuleBuilder()
.setDriver(Driver.class)
.runningOn(server)
.addEntityClass(AccountImpl.class)
.setExceptionHandler(H2ExceptionHandler.class)
.build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class)
.toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
bind(new TypeLiteral<TckRepository<AccountImpl>>() {})
.toInstance(new JpaTckRepository<>(AccountImpl.class));
bind(AccountDao.class).to(JpaAccountDao.class);
}
示例7: configure
import org.h2.Driver; //导入依赖的package包/类
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(
new PersistTestModuleBuilder()
.setDriver(Driver.class)
.runningOn(server)
.addEntityClasses(SshPairImpl.class, UserImpl.class, AccountImpl.class)
.setExceptionHandler(H2ExceptionHandler.class)
.build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class)
.toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
bind(SshDao.class).to(JpaSshDao.class);
bind(new TypeLiteral<TckRepository<SshPairImpl>>() {})
.toInstance(new JpaTckRepository<>(SshPairImpl.class));
bind(new TypeLiteral<TckRepository<UserImpl>>() {})
.toInstance(new JpaTckRepository<>(UserImpl.class));
}
示例8: configure
import org.h2.Driver; //导入依赖的package包/类
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(
new PersistTestModuleBuilder()
.setDriver(Driver.class)
.runningOn(server)
.addEntityClasses(InstallerImpl.class, InstallerServerConfigImpl.class)
.setExceptionHandler(H2ExceptionHandler.class)
.build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class)
.toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server.getDataSource()));
bind(new TypeLiteral<TckRepository<InstallerImpl>>() {}).to(InstallerJpaTckRepository.class);
bind(InstallerDao.class).to(JpaInstallerDao.class);
}
示例9: getPlatform
import org.h2.Driver; //导入依赖的package包/类
@Override
public IDatabasePlatform getPlatform() {
if (databasePlatform == null) {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(Driver.class.getName());
ds.setUrl("jdbc:h2:mem:" + name);
databasePlatform = JdbcDatabasePlatformFactory.createNewPlatformInstance(ds, new SqlTemplateSettings(), true, false);
StringBuilder bigTable = new StringBuilder("create table big (id integer");
for (int i = 0; i < 300; i++) {
bigTable.append(",col").append(Integer.toString(i)).append(" text");
}
bigTable.append(")");
databasePlatform.getSqlTemplate().update(bigTable.toString());
}
return databasePlatform;
}
示例10: getArgv
import org.h2.Driver; //导入依赖的package包/类
@Override
protected String[] getArgv(boolean includeHadoopFlags, int rowsPerStmt,
int statementsPerTx, String... additionalArgv) {
// we need different class names per test, or the classloader will
// just use the old class definition even though we've compiled a
// new one!
String[] args = newStrArray(additionalArgv, "--" + ExportTool.CALL_ARG,
PROCEDURE_NAME, "--" + ExportTool.CLASS_NAME_ARG, getName(), "--"
+ ExportTool.CONN_MANAGER_CLASS_NAME,
GenericJdbcManager.class.getName(), "--" + ExportTool.DRIVER_ARG,
Driver.class.getName());
return super
.getArgv(includeHadoopFlags, rowsPerStmt, statementsPerTx, args);
}
示例11: getCodeGenArgv
import org.h2.Driver; //导入依赖的package包/类
@Override
protected String[] getCodeGenArgv(String... extraArgs) {
String[] myExtraArgs = newStrArray(extraArgs, "--"
+ ExportTool.CONN_MANAGER_CLASS_NAME,
GenericJdbcManager.class.getName(), "--" + ExportTool.DRIVER_ARG,
Driver.class.getName());
return super.getCodeGenArgv(myExtraArgs);
}
示例12: getSqoopOptions
import org.h2.Driver; //导入依赖的package包/类
/**
* This gets called during {@link #setUp()} to check the non-HSQLDB database
* is valid. We'll therefore set the connection manager here...
*/
@Override
protected SqoopOptions getSqoopOptions(Configuration conf) {
SqoopOptions ret = new SqoopOptions(conf);
if (ret.getConnManagerClassName() == null) {
ret.setConnManagerClassName(GenericJdbcManager.class.getName());
}
if (ret.getDriverClassName() == null) {
ret.setDriverClassName(Driver.class.getName());
}
return ret;
}
示例13: getDataSource
import org.h2.Driver; //导入依赖的package包/类
@Bean
public DataSource getDataSource() {
return new SimpleDriverDataSource(new Driver(),
"jdbc:h2:mem:test-services;DB_CLOSE_DELAY=-1;LOCK_MODE=0",
"sa",
"");
}
示例14: init
import org.h2.Driver; //导入依赖的package包/类
@Override
public void init(String... args) {
port = Constants.DEFAULT_TCP_PORT;
for (int i = 0; args != null && i < args.length; i++) {
String a = args[i];
if (Tool.isOption(a, "-trace")) {
trace = true;
} else if (Tool.isOption(a, "-tcpSSL")) {
ssl = true;
} else if (Tool.isOption(a, "-tcpPort")) {
port = Integer.decode(args[++i]);
portIsSet = true;
} else if (Tool.isOption(a, "-tcpPassword")) {
managementPassword = args[++i];
} else if (Tool.isOption(a, "-baseDir")) {
baseDir = args[++i];
} else if (Tool.isOption(a, "-key")) {
key = args[++i];
keyDatabase = args[++i];
} else if (Tool.isOption(a, "-tcpAllowOthers")) {
allowOthers = true;
} else if (Tool.isOption(a, "-tcpDaemon")) {
isDaemon = true;
} else if (Tool.isOption(a, "-ifExists")) {
ifExists = true;
}
}
org.h2.Driver.load();
}
示例15: takeSnapshot
import org.h2.Driver; //导入依赖的package包/类
@Override
public void takeSnapshot(long sequenceNum) {
System.out.printf("APP begin takeSnapshot=%d\n", sequenceNum);
// if(lastSnapshotNum==sequenceNum) return; //vanderong
lastSnapshotNum=sequenceNum;
System.out.println("take checkpoint at "+sequenceNum+" time="+System.currentTimeMillis());
Properties prop = new Properties();
prop.setProperty("user", "sa");
prop.setProperty("password", "");
try{
Connection conn = Driver.load().connect("jdbc:h2:/test/tpcc", prop);
Statement stat = null;
stat = conn.createStatement();
stat.execute("CHECKPOINT SYNC");
Process p = Runtime.getRuntime().
exec("/usr/sbin/btrfs subvolume snapshot -r /test /test/backup"+sequenceNum);
p.waitFor();
p = Runtime.getRuntime().exec("sync");
p.waitFor();
System.out.println("end take checkpoint at "+sequenceNum+" time="+System.currentTimeMillis());
}
catch(Exception e){
e.printStackTrace();
System.exit(-1);
}
System.out.printf("APP finish takeSnapshot=%d\n", sequenceNum);
//libServerInterface.takeSnapshotComplete(sequenceNum); //vanderong
}