List of usage examples for org.apache.ibatis.jdbc ScriptRunner ScriptRunner
public ScriptRunner(Connection connection)
From source file:org.tomitribe.beryllium.db.DatabaseSteps.java
License:Apache License
@Given("^I have the following sql script \"([^\"]*)\"$") public void iHaveTheFollowingSQLScript(final String script) throws Throwable { new ScriptRunner(this.destination.getConnection()) .runScript(new BufferedReader(new FileReader(Resources.getResource(script).getPath()))); }
From source file:org.workspace7.osgi.mybatis.itests.KarafTestSupport.java
License:Apache License
void createAndDropH2Table(DataSource demodbDS) throws Exception { Connection connection = demodbDS.getConnection(); ScriptRunner scriptRunner = new ScriptRunner(connection); InputStreamReader sqlStreamReader = new InputStreamReader(getClass().getResourceAsStream("/h2_demodb.sql")); if (sqlStreamReader != null) { scriptRunner.runScript(sqlStreamReader); } else {// w w w . j a va2s . c o m throw new Exception("SQL File not found"); } }
From source file:org.wso2.carbon.cluster.utils.DBConnection.java
public static void runScript(Connection con, File sqlFile) throws Exception { ScriptRunner runner = new ScriptRunner(con); runner.setAutoCommit(true);/*www . j a v a 2 s . c o m*/ runner.runScript(new BufferedReader(new FileReader(sqlFile))); }
From source file:org.wso2.carbon.esb.samples.test.mediation.db.Sample364TestCase.java
License:Open Source License
public void addDB() throws Exception { File mysqlfile = new File(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts" + File.separator + "ESB" + File.separator + "sql" + File.separator + "system.sql"); File stock = new File(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts" + File.separator + "ESB" + File.separator + "sql" + File.separator + "mysqldata.sql"); Statement statement = mysqlConnection.createStatement(); statement.execute("DROP DATABASE IF EXISTS WSO2_CARBON_DB"); statement.execute("CREATE DATABASE IF NOT EXISTS WSO2_CARBON_DB"); statement.execute("USE WSO2_CARBON_DB"); ScriptRunner scriptRunner;/*from www . ja va 2 s. co m*/ scriptRunner = new ScriptRunner(mysqlConnection); // Give the input file to Reader Reader readerSystemData = new BufferedReader(new FileReader(mysqlfile)); // Exctute script scriptRunner.runScript(readerSystemData); Reader readerUserData = new BufferedReader(new FileReader(stock)); scriptRunner.runScript(readerUserData); }
From source file:org.wso2.carbon.esb.samples.test.miscellaneous.Sample657TestCase.java
License:Open Source License
public void addPhysicalDBonMySql(String dataSource) throws Exception { File mysqlfile = new File(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts" + File.separator + "ESB" + File.separator + "sql" + File.separator + "system.sql"); File stock = new File(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts" + File.separator + "ESB" + File.separator + "sql" + File.separator + "mysqldata.sql"); Statement statement = mysqlConnection.createStatement(); statement.execute("DROP DATABASE IF EXISTS " + dataSource); statement.execute("CREATE DATABASE IF NOT EXISTS " + dataSource); statement.execute("USE " + dataSource); ScriptRunner scriptRunner;// w w w . j a v a2s. c om scriptRunner = new ScriptRunner(mysqlConnection); // Give the input file to Reader Reader readerSystemData = new BufferedReader(new FileReader(mysqlfile)); Reader readerUserData = new BufferedReader(new FileReader(stock)); // Execute script scriptRunner.runScript(readerSystemData); scriptRunner.runScript(readerUserData); }
From source file:sergey.ibudgetapp.dao.impl.TestDataConnection.java
public static void initDatabase() { Connection connection = null; Reader reader = null;// w ww. ja v a2 s . c om try { connection = MyBatisUtil.getConnection(); ScriptRunner scriptRunner = new ScriptRunner(connection); // DatabaseMetaData dbmd = connection.getMetaData(); // ResultSet rs = dbmd.getTables(null, "ROOT", null, null); // if (!rs.next()) { // System.out.println(" "); // } reader = Resources.getResourceAsReader("sql/drop_tables.sql"); scriptRunner.runScript(reader); reader = Resources.getResourceAsReader("sql/create_tables.sql"); scriptRunner.runScript(reader); reader = Resources.getResourceAsReader("sql/sample_data.sql"); scriptRunner.runScript(reader); connection.commit(); reader.close(); scriptRunner.closeConnection(); } catch (Exception ex) { Logger.getLogger(TestDataConnection.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:sopho.CreateDatabase.java
public void CreateDB() throws ClassNotFoundException, SQLException { PrefsHandler prefs = new PrefsHandler(); //getting the credentials from the preferencies String user = prefs.getPrefs("dbUser"); String pass = prefs.getPrefs("dbPass"); String dbIP = prefs.getPrefs("dbIP"); Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://" + dbIP + ":3306", user, pass); //we are using the myBatis library to create the initial database using an sql file as a template. InputStream in = CreateDatabase.class.getResourceAsStream("dbCreate.sql"); try {//from w ww . java2 s. c o m // Initialize object for ScriptRunner ScriptRunner sr = new ScriptRunner(conn); // Give the input file to Reader Reader reader = new BufferedReader(new InputStreamReader(in)); // Execute script sr.runScript(reader); } catch (Exception e) { System.err.println("Failed to Execute" + " The error is " + e.getMessage()); } }
From source file:uk.ac.surrey.ee.iot.s2w.store.TripleStoreStartup.java
public void runSqlScript() { try {/*from w w w.j a v a2 s .com*/ // Initialize object for ScripRunner ScriptRunner sr = new ScriptRunner(conn); // Give the input file to Reader Reader reader = new BufferedReader(new FileReader(tripleStoreScript)); // Execute script //sr.runScript(reader); RunScript.execute(conn, reader); } catch (FileNotFoundException e) { System.err.println("Failed to Execute" + tripleStoreScript + " The error is " + e.getMessage()); } catch (SQLException ex) { Logger.getLogger(TripleStoreStartup.class.getName()).log(Level.SEVERE, null, ex); } Statement stmt = null; ResultSet rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT * FROM employees"); } catch (SQLException ex) { Logger.getLogger(TripleStoreStartup.class.getName()).log(Level.SEVERE, null, ex); } }