Running a script to create tables with HSQLDB

前端 未结 4 1941
生来不讨喜
生来不讨喜 2021-02-04 17:24

I use hsqldb to run my unit tests that need a database access.

For the moment, when I want to create a table for a specific test, I have the following c

相关标签:
4条回答
  • 2021-02-04 17:53

    since you're already using spring, you might want to use the SimpleJdbcUtils.executeSQLScript method which executes an SQL script where the statements are separated with semicolon. this class is in the spring-test module (JAR).

    0 讨论(0)
  • 2021-02-04 17:54

    First of all, I do not know implications of this. I used it long time back it worked for me. The SQLExec class is from ant.jar, you can probably look into the ant source to create your own utility class,

    SQLExec sqlExec=new SQLExec();
    sqlExec.setUserid("user");
    sqlExec.setPassword("passowrd");
    sqlExec.setUrl("jdbc:mysql://localhost:3306/dbname");
    sqlExec.setDriver("com.mysql.jdbc.Driver");
    sqlExec.setProject(new Project());
    sqlExec.setSrc(new File("c:/test.sql"));
    sqlExec.execute();
    
    0 讨论(0)
  • 2021-02-04 18:07

    I had the same problem. I ended up splitting the text file by ; and executing each statement separately. It was OK because we had no inserts therefore no semicolons inside statements. I haven't found an easy way to run an SQL script at that time

    0 讨论(0)
  • 2021-02-04 18:16

    You might give org.hsqldb.util.SqlFile a try. This class seems to be a perfect match for your problem.

    0 讨论(0)
提交回复
热议问题