1 20 21 package org.apache.derbyTesting.functionTests.tests.jdbc4; 22 23 import org.apache.derbyTesting.junit.BaseJDBCTestCase; 24 import org.apache.derbyTesting.junit.BaseJDBCTestSetup; 25 26 import junit.framework.Test; 27 import junit.extensions.TestSetup; 28 29 import java.sql.*; 30 31 36 public class StatementTestSetup 37 extends BaseJDBCTestSetup { 38 39 45 public StatementTestSetup(Test test) { 46 super(test); 47 } 48 49 56 protected void setUp() 57 throws SQLException { 58 Connection con = getConnection(); 59 Statement stmt = con.createStatement(); 61 try { 63 stmt.execute("select count(*) from stmtTable"); 64 stmt.execute("drop table stmtTable"); 66 } catch (SQLException sqle) { 67 assertEquals("Unexpected error when accessing non-existing table.", 69 "42X05", 70 sqle.getSQLState()); 71 } 72 stmt.execute("create table stmtTable (id int, val varchar(10))"); 73 stmt.execute("insert into stmtTable values (1, 'one'),(2,'two')"); 74 ResultSet rs = stmt.executeQuery("select count(*) from stmtTable"); 77 rs.next(); 78 assertEquals("Number of rows are not as expected", 79 2, rs.getInt(1)); 80 rs.close(); 81 stmt.close(); 82 con.commit(); 83 } 84 85 91 protected void tearDown() 92 throws Exception { 93 Connection con = getConnection(); 94 Statement stmt = con.createStatement(); 95 stmt.execute("drop table stmtTable"); 96 stmt.close(); 97 con.commit(); 98 super.tearDown(); 99 } 100 101 } | Popular Tags |