Java Code Examples for org.hsqldb.cmdline.SqlFile

The following examples show how to use org.hsqldb.cmdline.SqlFile. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Executes a single sql file
 * 
 * @param sqlFile Path of the file to execute(it can be a classpath
 *        resource)
 * @throws IOException
 * @throws SqlToolError
 * @throws SQLException
 */
private void execute(String sqlFile) throws IOException, SQLException {
	log.debug("Execute " + sqlFile);
	System.out.println("Execute " + sqlFile);
	File file = new File(sqlFile);
	if (!file.exists() || !file.canRead()) {
		file = File.createTempFile(file.getName(), ".sql");
		file.deleteOnExit();
		FileUtil.copyResource(sqlFile, file);
	}

	SqlFile sFile = new SqlFile(file, "Cp1252", false);
	try {
		sFile.setContinueOnError(true);
		sFile.setConnection(con);
		sFile.execute();
	} catch (SqlToolError e) {
		throw new SQLException(e.getMessage());
	}
}
 
Example 2
Source Project: vibur-dbcp   Source File: HsqldbUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void deployDatabaseSchemaAndData(String jdbcUrl, String username, String password)
    throws IOException, SqlToolError, SQLException {

    Connection connection = null;
    try {
        connection = DriverManager.getConnection(jdbcUrl, username, password);
        InputStreamReader isr = new InputStreamReader(Thread.currentThread().getContextClassLoader()
            .getResourceAsStream(HSQLDB_SCHEMA_AND_DATA_SQL), System.getProperty("file.encoding"));
        SqlFile sqlFile = new SqlFile(isr, "--sql", System.out, null, false, null);
        sqlFile.setConnection(connection);
        sqlFile.execute();
    } finally {
        quietClose(connection);
    }
}