1 30 31 32 package org.hsqldb.test; 33 34 import java.sql.Connection ; 35 import java.sql.ResultSet ; 36 import java.sql.Statement ; 37 38 import junit.framework.TestCase; 39 import junit.framework.TestResult; 40 41 48 public class TestStoredProcedure extends TestBase { 49 50 public TestStoredProcedure(String name) { 51 super(name); 52 } 53 54 public void test() throws Exception { 55 56 Connection conn = newConnection(); 57 Statement statement; 58 int updateCount; 59 60 try { 61 statement = conn.createStatement(); 62 63 ResultSet rs = statement.executeQuery( 64 "call \"org.hsqldb.test.TestStoredProcedure.procTest1\"()"); 65 66 rs.next(); 67 68 int cols = rs.getInt(1); 69 70 assertTrue("test result not correct", cols == 2); 71 } catch (Exception e) { 72 assertTrue("unable to execute call to procedure", false); 73 } finally { 74 conn.close(); 75 } 76 77 conn = newConnection(); 78 79 try { 80 statement = conn.createStatement(); 81 } catch (Exception e) { 82 assertTrue("unexpected error", false); 83 } finally { 84 conn.close(); 85 } 86 } 87 88 public static int procTest1(Connection conn) 89 throws java.sql.SQLException { 90 91 int cols; 92 java.sql.Statement stmt = conn.createStatement(); 93 94 stmt.execute("CREATE temp TABLE MYTABLE(COL1 INTEGER,COL2 VARCHAR);"); 95 stmt.execute("INSERT INTO MYTABLE VALUES (1,'test1');"); 96 stmt.execute("INSERT INTO MYTABLE VALUES(2,'test2');"); 97 98 java.sql.ResultSet rs = stmt.executeQuery("select * from MYTABLE"); 99 java.sql.ResultSetMetaData meta = rs.getMetaData(); 100 101 cols = meta.getColumnCount(); 102 103 rs.close(); 104 stmt.close(); 105 106 return cols; 107 } 108 109 public static void main(String [] args) throws Exception { 110 111 TestResult result; 112 TestCase test; 113 java.util.Enumeration failures; 114 int count; 115 116 result = new TestResult(); 117 test = new TestStoredProcedure("test"); 118 119 test.run(result); 120 121 count = result.failureCount(); 122 123 System.out.println("TestStoredProcedure failure count: " + count); 124 125 failures = result.failures(); 126 127 while (failures.hasMoreElements()) { 128 System.out.println(failures.nextElement()); 129 } 130 } 131 } 132 | Popular Tags |