Java代码
- String aSQLScriptFilePath = "/script.sql";
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(
- "jdbc:mysql://localhost:3306/database", "username", "password");
- Statement stmt = null;
- try {
- ScriptRunner sr = new ScriptRunner(con, false, false);
- Reader reader = new BufferedReader(
- new FileReader(aSQLScriptFilePath));
- sr.runScript(reader);
- } catch (Exception e) {
- System.err.println("Failed to Execute" + aSQLScriptFilePath
- + " The error is " + e.getMessage());
- }