Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. # Setting up DAL to work with in-memory hsql db
  2.  
  3. 1.Add reference to maven lib in pom.xml
  4. ```xml
  5. <properties>
  6. <hsqldb.version>2.3.2</hsqldb.version>
  7. </properties>
  8. <dependency>
  9. <groupId>org.hsqldb</groupId>
  10. <artifactId>hsqldb</artifactId>
  11. <version>${hsqldb.version}</version>
  12. </dependency>
  13. ```
  14. When we run maven project a file with the test database will be created in root project pom
  15. in our case db is testdb
  16.  
  17. # Download sql manager and put below
  18.  
  19. jdbc:hsqldb:file:D:\prkale\git\ecgs05\ecgs\testdb
  20.  
  21. #initialize hsql
  22.  
  23. ```
  24. @BeforeClass
  25. public final static void beforeClass() throws SQLException, IOException {
  26.  
  27. try {
  28. Class.forName("org.hsqldb.jdbc.JDBCDriver");
  29. } catch (ClassNotFoundException e) {
  30. throw new RuntimeException("Cannot load hsql driver.", e);
  31. }
  32.  
  33. conn = DriverManager.getConnection("jdbc:hsqldb:testdb", "SA", "SA");
  34. conn.setAutoCommit(true);
  35.  
  36. ClassLoader cl = BaseTest.class.getClassLoader();
  37.  
  38. String createStm = IOUtils.toString(cl.getResourceAsStream("db/create-db.sql"));
  39. String insertStm = IOUtils.toString(cl.getResourceAsStream("db/insert-data.sql"));
  40.  
  41. conn.createStatement().executeUpdate(createStm);
  42.  
  43. PreparedStatement psInsert = conn.prepareStatement(insertStm);
  44. int updated = psInsert.executeUpdate();
  45. }
  46.  
  47. @AfterClass
  48. public final static void afterClass() throws SQLException {
  49. if (conn != null) {
  50. conn.close();
  51. }
  52. }
  53.  
  54.  
  55. //@PostConstruct
  56. public void getDbManager() {
  57. DatabaseManagerSwing.main(
  58. new String[]{"--url", "jdbc:hsqldb:testdb", "--user", "SA", "--password", "SA"});
  59. }
  60.  
  61. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement