List of usage examples for org.apache.ibatis.jdbc ScriptRunner runScript
public void runScript(Reader reader)
From source file:br.jpe.dallahits.script.core.InicializadorDB.java
/** * Roda o script de criao das tabelas// w w w . ja v a 2 s . com * * @param sr ScriptRunner * @throws FileNotFoundException */ private void criaTabelas(ScriptRunner sr) throws FileNotFoundException { sr.runScript(getReaderFor(SC_TABLES)); }
From source file:br.jpe.dallahits.script.core.InicializadorDB.java
/** * Roda o script de inicializao dos dados * * @param sr ScriptRunner//w w w. j a v a 2 s.c o m * @throws FileNotFoundException */ private void inicializaDados(ScriptRunner sr) throws FileNotFoundException { sr.runScript(getReaderFor(SC_INIT)); }
From source file:br.jpe.dallahits.script.core.InicializadorDB.java
/** * Roda o script de criao das tabelas/* ww w.ja v a 2 s.c o m*/ * * @param sr ScriptRunner * @throws FileNotFoundException */ private void criaViews(ScriptRunner sr) throws FileNotFoundException { sr.runScript(getReaderFor(SC_VIEWS)); }
From source file:com.collective.messages.persistence.dao.BaseDataTestCase.java
License:Apache License
public static void runScript(ScriptRunner runner, String resource) throws IOException, SQLException { Reader reader = Resources.getResourceAsReader(resource); try {/* w w w . ja v a2 s . co m*/ runner.runScript(reader); } finally { reader.close(); } }
From source file:com.daemon.SearchTermTest.java
License:Open Source License
@BeforeClass public static void prepareDatabase() throws SQLException { try {/*from ww w. j ava 2s. com*/ transactor = new Transactor(); connection = DriverManager.getConnection(transactor.getDbUrl()); // Prepare database Reader reader = Resources.getResourceAsReader("DaemonDump.sql"); ScriptRunner sr = new ScriptRunner(connection); sr.setDelimiter(";"); sr.setLogWriter(null); sr.setErrorLogWriter(null); sr.runScript(reader); connection.commit(); reader.close(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (SQLException sqle) { sqle.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { connection.close(); } }
From source file:com.daemon.TransactorTest.java
License:Open Source License
@BeforeClass public static void beforeClass() { try {/* w w w . j a va2 s . co m*/ _dbPath = Transactor.DATABASE_PROPERTY_PATH; URL url = Resources.getResourceURL("database.properties"); Transactor.DATABASE_PROPERTY_PATH = URLDecoder.decode(url.getFile(), "UTF-8"); _trans = new Transactor(); _trans.connect(); // Prepare database Reader reader = Resources.getResourceAsReader("DaemonDump.sql"); ScriptRunner sr = new ScriptRunner(_trans.getConnection()); sr.setDelimiter(";"); sr.setLogWriter(null); sr.setErrorLogWriter(null); sr.runScript(reader); _trans.getConnection().commit(); reader.close(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (SQLException sqle) { sqle.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.google.enterprise.connector.db.DBTestBase.java
License:Apache License
/** * Executes the database script./*from w w w . j av a2s. c o m*/ * * @param scriptPath path of SQL script file */ protected void runDBScript(String scriptPath) throws Exception { ScriptRunner runner = new ScriptRunner(dbConnection); runner.setStopOnError(true); runner.runScript(Resources.getResourceAsReader(scriptPath)); }
From source file:com.jcin.cms.web.setup.SetupController.java
/** * 3.?/*from w w w. j a v a 2 s.c o m*/ * * @return */ @RequestMapping(value = "/finish") public String finish(@Valid Hostsetting hostsetting, BindingResult result, Model uiModel, HttpServletRequest httpServletRequest, HttpServletResponse response) { if (result.hasErrors()) { populateEditForm(uiModel, hostsetting); return "database"; } URL url = SetupController.class.getClassLoader().getResource(""); String filePath = url.getPath(); filePath += "database" + File.separator + "db.sql"; File file = new File(filePath); String dbdriver = "com.mysql.jdbc.Driver"; String dburl = "jdbc:mysql://" + hostsetting.getHost() + ":" + hostsetting.getPort() + "/" + hostsetting.getDbname(); Connection con = null; // ? // PrintWriter out = null; String object = ""; try { // out = response.getWriter(); Class.forName(dbdriver).newInstance(); con = DriverManager.getConnection(dburl, hostsetting.getUsername(), hostsetting.getPassword()); // 2?? ScriptRunner runner = new ScriptRunner(con); InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "UTF-8"); runner.runScript(isr); if (con != null) object = "success"; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } finally { if (!object.equals("success")) object = "?url,???????"; // out.write(object); // out.flush(); // out.close(); } return "redirect:/setup/success"; }
From source file:com.jcin.SetUpServlet.java
/** * ?//from w ww.j av a 2 s . com * * @param request * @param response * @throws ServletException * @throws IOException */ public void setup(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String filePath = this.getServletConfig().getServletContext().getRealPath("/"); filePath += "database" + File.separator + "createDatabase.sql"; File file = new File(filePath); System.out.println(filePath); String host = request.getParameter("host"); if (host == null || "".equals(host)) { host = "localhost"; } String port = request.getParameter("port"); if (port == null || "".equals(port)) { port = "3306"; } String databasename = request.getParameter("databasename"); if (databasename == null || "".equals(databasename)) { databasename = "test"; } String user = request.getParameter("user"); if (user == null || "".equals(user)) { user = "root"; } String password = request.getParameter("password"); if (password == null || "".equals(password)) { password = "qwer123456"; } String dbdriver = "com.mysql.jdbc.Driver"; String dburl = "jdbc:mysql://" + host + ":" + port + "/" + databasename; Connection con = null; // ? PrintWriter out = response.getWriter(); String result = "fail"; try { Class.forName(dbdriver).newInstance(); con = DriverManager.getConnection(dburl, user, password); // 2?? ScriptRunner runner = new ScriptRunner(con); Reader reader = new FileReader(file); runner.runScript(reader); result = "?"; } catch (ClassNotFoundException e) { if (out == null) { out = response.getWriter(); } result = "Could not found Class"; e.printStackTrace(); } // 1?CLASS ? catch (SQLException e) { if (out == null) { out = response.getWriter(); } result = "?url,???????"; e.printStackTrace(); } catch (InstantiationException e) { if (out == null) { out = response.getWriter(); } result = ""; e.printStackTrace(); } catch (IllegalAccessException e) { if (out == null) { out = response.getWriter(); } result = "??"; e.printStackTrace(); } finally { try { con.close(); } catch (SQLException e) { result = "?"; e.printStackTrace(); } } if (out != null) { out.write("success"); out.flush(); out.close(); } // response.sendRedirect(request.getContextPath() // + "/license.jsp"); }
From source file:com.persinity.common.db.SimpleRelDb.java
License:Apache License
@Override public void executeScript(final String scriptName) { notEmpty("scriptName"); if (scriptRunner == null) { scriptRunner = new ScriptRunner(getConnection()); configure(scriptRunner);/* w w w . ja v a2 s.c o m*/ } final ScriptRunner _scriptRunner = scriptRunner; final InputStream resourceStream = ClassLoader.getSystemResourceAsStream(scriptName); assertArg(resourceStream != null, "Failed to find script: {}", scriptName); final Reader scriptReader = new InputStreamReader(resourceStream); log("Executing DB script ", Collections.singletonList(scriptName)); resource.accessAndAutoClose(new Accessor<Reader, Void>(scriptReader, scriptName) { @Override public Void access(final Reader resource) throws Exception { _scriptRunner.runScript(new BufferedReader(scriptReader)); return null; } }); }