com.ibatis.common.jdbc.ScriptRunner Java Examples

The following examples show how to use com.ibatis.common.jdbc.ScriptRunner. 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
Source File: PostgresStorageTest.java    From cassandra-reaper with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws SQLException, IOException {
  Server.createTcpServer().start();

  DBI dbi = new DBI(DB_URL);
  Handle handle = dbi.open();
  Connection conn = handle.getConnection();

  // to suppress output of ScriptRunner
  PrintStream tmp = new PrintStream(new OutputStream() {
    @Override
    public void write(int buff) throws IOException {
      // do nothing
    }
  });
  PrintStream console = System.out;
  System.setOut(tmp);

  String cwd = Paths.get("").toAbsolutePath().toString();
  String path = cwd + "/../src/test/resources/db/postgres/V17_0_0__multi_instance.sql";
  ScriptRunner scriptExecutor = new ScriptRunner(conn, false, true);
  Reader reader = new BufferedReader(new FileReader(path));
  scriptExecutor.runScript(reader);

  System.setOut(console);
}
 
Example #2
Source File: DatabaseServerPreparingInitializer.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 5 votes vote down vote up
public void runScriptFile() {
	
	final InformationFrame dialog = new InformationFrame();
	final String sqlFilePath = "src/com/coder/hms/connection/hotel_management_system.sql";
	final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
	final String DB_CONNECTION = "jdbc:mysql://localhost:3306/";
	String DB_USER = JOptionPane.showInputDialog(this, "Enter your database user name :", "Coder HMS [Input]", JOptionPane.QUESTION_MESSAGE);
	String DB_PASSWORD = JOptionPane.showInputDialog(this, "Enter your database password :", "Coder HMS [Input]", JOptionPane.QUESTION_MESSAGE);
	
		try {
			
			Class.forName(DB_DRIVER);
			Connection connection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);
			
			ScriptRunner runner = new ScriptRunner(connection, false, false);
			Reader br = new BufferedReader(new FileReader(sqlFilePath));

			file = new File(System.getProperty("user.dir")+ File.separator + "Logging Store/SQL_Logs.txt");
			PrintWriter writer = new PrintWriter(file);
			runner.setLogWriter(writer);
			runner.runScript(br);
			dialog.setMessage("Your database and tables created successfully.");
			
			status = true;
			
		} catch (SQLException | ClassNotFoundException | IOException ex) {
			dialog.setMessage(ex.getMessage());
			status = false;
		}
	
	dialog.setVisible(true);
}
 
Example #3
Source File: DbUtil.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
private static void setupDB() throws SQLException, IOException {
    Connection connection = DriverManager.getConnection(DATABASE_URL + ";create=true");

    ScriptRunner scriptRunner = new ScriptRunner(connection, true, true);
    scriptRunner.runScript(new BufferedReader(new FileReader(path)));
    connection.close();
}
 
Example #4
Source File: DbUtil.java    From ballerina-message-broker with Apache License 2.0 5 votes vote down vote up
private static void setupDB() throws SQLException, IOException {
    Connection connection = DriverManager.getConnection(DATABASE_URL + ";create=true");

    ScriptRunner scriptRunner = new ScriptRunner(connection, true, true);
    scriptRunner.runScript(new BufferedReader(new FileReader(path)));
    connection.close();
}
 
Example #5
Source File: DbUtils.java    From ballerina-message-broker with Apache License 2.0 3 votes vote down vote up
public static void setupDB() throws SQLException, IOException {

        Connection connection = DriverManager.getConnection(DATABASE_URL + ";create=true");

        ScriptRunner scriptRunner = new ScriptRunner(connection, true, true);
        scriptRunner.runScript(new BufferedReader(new FileReader(path)));

        connection.close();
    }