Java源码示例:org.hsqldb.cmdline.SqlFile

示例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());
	}
}
 
示例2
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);
    }
}