当前位置: 首页>>代码示例>>Java>>正文


Java RunScript.execute方法代码示例

本文整理汇总了Java中org.h2.tools.RunScript.execute方法的典型用法代码示例。如果您正苦于以下问题:Java RunScript.execute方法的具体用法?Java RunScript.execute怎么用?Java RunScript.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.tools.RunScript的用法示例。


在下文中一共展示了RunScript.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.h2.tools.RunScript; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
  registry = RegistryService.getMetricRegistry();

  String sqlId = new StringUniqueIdService().getUniqueId(SELECT_QUERY);
  executeStatementName = JdbcRuleHelper.EXECUTE_STATEMENT_NAME.withTags("sql", sqlId);

  presetElements = IntStream.range(0, 1000).boxed()
      .collect(Collectors.toMap(i -> UUID.randomUUID().toString(), i -> i));
  presetElementKeys = new ArrayList<>(presetElements.keySet());

  StringBuilder sb = new StringBuilder(CREATE_TABLE_STRING);
  presetElements.forEach((s, o) -> {
    sb.append("\nINSERT INTO TEST VALUES('").append(s).append("', ").append(o).append(");");
  });

  String dbName = "JDBCInstrumentationTest." + UUID.randomUUID();
  datasource = JdbcConnectionPool.create("jdbc:h2:mem:" + dbName, "h2", "h2");
  ((JdbcConnectionPool) datasource).setMaxConnections(POOL_SIZE);
  datasource.setLoginTimeout(-1);
  Connection conn = datasource.getConnection();
  RunScript.execute(conn, new StringReader(sb.toString()));
  conn.close();
}
 
开发者ID:ApptuitAI,项目名称:JInsight,代码行数:25,代码来源:JDBCInstrumentationTest.java

示例2: initDb

import org.h2.tools.RunScript; //导入方法依赖的package包/类
/**
 * Initialize a database from a SQL script file.
 */
void initDb() throws Exception {
    Class.forName("org.h2.Driver");
    InputStream in = getClass().getResourceAsStream("script.sql");
    if (in == null) {
        System.out.println("Please add the file script.sql to the classpath, package "
                + getClass().getPackage().getName());
    } else {
        Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
        RunScript.execute(conn, new InputStreamReader(in));
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
        rs.close();
        stat.close();
        conn.close();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:InitDatabaseFromJar.java

示例3: main

import org.h2.tools.RunScript; //导入方法依赖的package包/类
/**
 * This method is called when executing this sample application from the
 * command line.
 *
 * @param args the command line parameters
 */
public static void main(String... args) throws Exception {
    String targetDir = args.length == 0 ? "." : args[0];
    Class.forName("org.h2.Driver");
    Connection conn = DriverManager.getConnection("jdbc:h2:mem:", "sa", "");
    InputStream in = Newsfeed.class.getResourceAsStream("newsfeed.sql");
    ResultSet rs = RunScript.execute(conn, new InputStreamReader(in, "ISO-8859-1"));
    in.close();
    while (rs.next()) {
        String file = rs.getString("FILE");
        String content = rs.getString("CONTENT");
        if (file.endsWith(".txt")) {
            content = convertHtml2Text(content);
        }
        new File(targetDir).mkdirs();
        FileOutputStream out = new FileOutputStream(targetDir + "/" + file);
        Writer writer = new OutputStreamWriter(out, "UTF-8");
        writer.write(content);
        writer.close();
        out.close();
    }
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:29,代码来源:Newsfeed.java

示例4: TestServer

import org.h2.tools.RunScript; //导入方法依赖的package包/类
private TestServer() {
    DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
    try (Connection connection = ds.getConnection()) {
        String schemaResourceName = "/create_h2.sql";
        InputStream in = TestServer.class.getResourceAsStream(schemaResourceName);

        if (in == null) {
            throw new RuntimeException("Failed to load resource: " + schemaResourceName);
        }
        InputStreamReader reader = new InputStreamReader(in, UTF_8);
        RunScript.execute(connection, reader);

    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:17,代码来源:TestServer.java

示例5: TestServer

import org.h2.tools.RunScript; //导入方法依赖的package包/类
private TestServer() {
    DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
    try (Connection connection = ds.getConnection()) {
        String schemaResourceName = "/create_h2.sql";
        InputStream in = TestServer.class.getResourceAsStream(schemaResourceName);

        if (in == null) {
            throw new RuntimeException("Failed to load resource: " + schemaResourceName);
        }
        InputStreamReader reader = new InputStreamReader(in, UTF_8);
        RunScript.execute(connection, reader);

    } catch (SQLException e) {
        e.printStackTrace();
    }

}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:18,代码来源:TestServer.java

示例6: TestServer

import org.h2.tools.RunScript; //导入方法依赖的package包/类
private TestServer() {
    DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
    try (Connection connection = ds.getConnection()) {
        // Runscript doesn't work need to execute batch here.
        String schemaResourceName = "/create_h2.sql";
        InputStream in = TestServer.class.getResourceAsStream(schemaResourceName);

        if (in == null) {
            throw new RuntimeException("Failed to load resource: " + schemaResourceName);
        }
        InputStreamReader reader = new InputStreamReader(in, UTF_8);
        RunScript.execute(connection, reader);

    } catch (SQLException e) {
        e.printStackTrace();
    }
}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:18,代码来源:TestServer.java

示例7: runOnceBeforeClass

import org.h2.tools.RunScript; //导入方法依赖的package包/类
@BeforeClass
public static void runOnceBeforeClass() {
    System.out.println("@BeforeClass - runOnceBeforeClass");
    DataSource ds = (DataSource) SingletonServiceFactory.getBean(DataSource.class);
    try (Connection connection = ds.getConnection()) {
        String schemaResourceName = "/create_h2.sql";
        InputStream in = CacheStartupHookProviderTest.class.getResourceAsStream(schemaResourceName);

        if (in == null) {
            throw new RuntimeException("Failed to load resource: " + schemaResourceName);
        }
        InputStreamReader reader = new InputStreamReader(in, UTF_8);
        RunScript.execute(connection, reader);

    } catch (SQLException e) {
        e.printStackTrace();
    }

}
 
开发者ID:networknt,项目名称:light-oauth2,代码行数:20,代码来源:CacheStartupHookProviderTest.java

示例8: initDb

import org.h2.tools.RunScript; //导入方法依赖的package包/类
public DatabaseEngine initDb() {
    try {
        ResourceUtil ru = new ResourceUtil();
        Class.forName("org.h2.Driver");
        InputStream in = ru.getResourceAsStream("sql/create.sql");
        InputStream in2 = ru.getResourceAsStream("sql/fill.sql");
        if (in == null) {
            System.out.println("Please add the file create.sql to the classpath, package "
                    + getClass().getPackage().getName());
        } else {
            setConnection(DriverManager.getConnection(H2_DB_URL, "admin", "admin"));
            RunScript.execute(connection, new InputStreamReader(in));
            RunScript.execute(connection, new InputStreamReader(in2));
        }
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    }

    return this;
}
 
开发者ID:nuclearthinking,项目名称:rpg,代码行数:21,代码来源:DatabaseEngine.java

示例9: initDb

import org.h2.tools.RunScript; //导入方法依赖的package包/类
/**
 * Initialize a database from a SQL script file.
 */
void initDb() throws Exception {
    ResourceUtil ru = new ResourceUtil();
    Class.forName("org.h2.Driver");
    InputStream in = ru.getResourceAsStream("sql/init.sql");
    ru = null;
    if (in == null) {
        System.out.println("Please add the file script.sql to the classpath, package "
                + getClass().getPackage().getName());
    } else {
        Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
        RunScript.execute(conn, new InputStreamReader(in));
        Statement stat = conn.createStatement();
        ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
        rs.close();
        stat.close();
        conn.close();
    }
}
 
开发者ID:nuclearthinking,项目名称:rpg,代码行数:25,代码来源:InitDbForJar.java

示例10: H2CacheStoreStrategy

import org.h2.tools.RunScript; //导入方法依赖的package包/类
/**
 * @throws IgniteCheckedException If failed.
 */
public H2CacheStoreStrategy() throws IgniteCheckedException {
    Server srv = null;

    try {
        srv = Server.createTcpServer().start();

        port = srv.getPort();

        dataSrc = H2CacheStoreSessionListenerFactory.createDataSource(port);

        try (Connection conn = connection()) {
            RunScript.execute(conn, new StringReader(CREATE_CACHE_TABLE));
            RunScript.execute(conn, new StringReader(CREATE_STATS_TABLES));
            RunScript.execute(conn, new StringReader(POPULATE_STATS_TABLE));
        }
    }
    catch (SQLException e) {
        throw new IgniteCheckedException("Failed to set up cache store strategy" +
            (srv == null ? "" : ": " + srv.getStatus()), e);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:25,代码来源:H2CacheStoreStrategy.java

示例11: runScript

import org.h2.tools.RunScript; //导入方法依赖的package包/类
public int runScript(InputStream script, String encoding) throws Exception {
  ResultSet results = RunScript.execute(getConnection(), new InputStreamReader(script));

  if (results != null)
    results.close();

  return 0;
}
 
开发者ID:RuiChen08,项目名称:dacapobench,代码行数:9,代码来源:TPCC.java

示例12: loadDriverTest

import org.h2.tools.RunScript; //导入方法依赖的package包/类
@BeforeClass
public static void loadDriverTest() throws Exception {
    Class.forName("org.h2.Driver");
    activeConn = getConnection();

    Connection conn = getConnection();
    RunScript.execute(conn, new FileReader("src/test/resources/testdb.ddl"));
    conn.close();
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:10,代码来源:QueryDataSourceTest.java

示例13: compact

import org.h2.tools.RunScript; //导入方法依赖的package包/类
/**
 * Utility method to compact a database.
 *
 * @param dir the directory
 * @param dbName the database name
 * @param user the user name
 * @param password the password
 */
public static void compact(String dir, String dbName,
        String user, String password) throws SQLException {
    String url = "jdbc:h2:" + dir + "/" + dbName;
    String file = "data/test.sql";
    Script.process(url, user, password, file, "", "");
    DeleteDbFiles.execute(dir, dbName, true);
    RunScript.execute(url, user, password, file, null, false);
    FileUtils.delete(file);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:18,代码来源:Compact.java

示例14: setUp

import org.h2.tools.RunScript; //导入方法依赖的package包/类
@Before
public void setUp() throws SQLException {
    final JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    dataSource.setUser("sa");
    dataSource.setPassword("");

    final Connection connection = dataSource.getConnection();
    RunScript.execute(connection, new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("test.sql")));
    System.out.println("Created in-memory database: " + connection.getMetaData().getURL());

    connectionManager = new CountingConnectionManager(new DataSourceConnectionManager(dataSource));
    toTest = new JdbcOperations(connectionManager);
}
 
开发者ID:voho,项目名称:jdbcis,代码行数:15,代码来源:AbstractOperationTest.java

示例15: runScript

import org.h2.tools.RunScript; //导入方法依赖的package包/类
private void runScript(String fileName) throws SQLException, IOException {
    Connection connection = null;
    try {
        connection = connectionBuilder.getConnection();
        RunScript.execute(connection, load(fileName));
    } finally {
        connection.close();
    }
}
 
开发者ID:hortonworks,项目名称:registry,代码行数:10,代码来源:DbFileStorageTest.java


注:本文中的org.h2.tools.RunScript.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。