1 4 package org.oddjob.hsql; 5 6 import java.sql.Connection ; 7 import java.sql.DriverManager ; 8 import java.sql.ResultSet ; 9 import java.sql.Statement ; 10 11 import junit.framework.TestCase; 12 13 public class HsqldbJobTest extends TestCase { 14 15 public void test1() throws Exception { 16 HsqldbJob test = new HsqldbJob(); 17 18 test.setDatabase("mydb", "file:test/persist/hsql"); 19 test.setProperty("server.port", "11001"); 20 test.setProperty("server.silent", "false"); 21 22 test.start(); 23 24 try { 25 Class.forName("org.hsqldb.jdbcDriver" ); 26 Connection c = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:11001/mydb", "sa", ""); 27 28 Statement s = c.createStatement(); 29 s.executeUpdate("create table test (greeting varchar(10))"); 30 s.executeUpdate("insert into test values ('hello')"); 31 s.close(); 32 c.close(); 33 } finally { 34 test.stop(); 35 } 36 } 37 38 public void test2() throws Exception { 39 HsqldbJob test = new HsqldbJob(); 40 41 test.setDatabase("mydb", "file:test/persist/hsql"); 42 test.setProperty("server.port", "11001"); 43 test.setProperty("server.silent", "false"); 44 45 test.start(); 46 47 try { 48 Class.forName("org.hsqldb.jdbcDriver" ); 49 Connection c = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:11001/mydb", "sa", ""); 50 51 Statement s = c.createStatement(); 52 ResultSet r = s.executeQuery("select * from test"); 53 r.next(); 54 assertEquals("hello", r.getString(1)); 55 s.close(); 56 c.close(); 57 } 58 finally { 59 test.stop(); 60 } 61 } 62 63 64 } 65 | Popular Tags |