Execute SQL file from Spring JDBC Template

后端 未结 4 912
我在风中等你
我在风中等你 2021-02-05 06:44

I\'m trying to write a bit of code that reads a SQL file (multiple CREATE TABLE statements separated by ;) and executes all the statements.

In

4条回答
  •  逝去的感伤
    2021-02-05 07:21

    try it

    public void executeSqlScript(Connection connection,StringBuffer sql)throws SQLException{
             try {
                 connection.setAutoCommit(false);//设置为手工提交模式  
                 ScriptUtils.executeSqlScript(connection, new ByteArrayResource(sql.toString().getBytes()));
                 connection.commit();//提交事务  
            } catch (SQLException e) {
                connection.rollback();
            }finally{
                connection.close();
            }
         }
    

提交回复
热议问题