版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/vcshcn/article/details/50673191
import org.apache.ibatis.jdbc.ScriptRunner;
public static void run(String driver, String url, String user, String password, String sqlfile) throws ClassNotFoundException, SQLException, IOException {
Class.forName(driver);
try (
Reader reader = new BufferedReader(new FileReader(sqlfile));
Connection connection = DriverManager.getConnection(url, user,password);
)
{
ScriptRunner runner = new ScriptRunner(connection);
runner.setAutoCommit(false);
runner.setSendFullScript(true);
runner.runScript(reader);
}
}