1 21 22 package org.apache.derbyTesting.functionTests.tests.lang; 23 24 import java.net.URL ; 25 import java.net.URLClassLoader ; 26 import java.sql.Connection ; 27 import java.sql.ResultSet ; 28 import java.sql.SQLException ; 29 import java.sql.Statement ; 30 31 import org.apache.derby.tools.ij; 32 33 46 public class AggregateClassLoading { 47 48 public static void main(String [] args) throws Exception { 49 50 System.out.println("Test AggregateClassLoading starting"); 51 52 ij.getPropertyArg(args); 55 Connection conn = ij.startJBMS(); 56 57 URL derbyURL = conn.getClass().getProtectionDomain().getCodeSource().getLocation(); 60 61 URLClassLoader cl = new URLClassLoader (new URL [] {derbyURL}, null); 68 Thread.currentThread().setContextClassLoader(cl); 69 70 Statement s = conn.createStatement(); 71 72 s.execute("create table t (i int)"); 73 s.execute("insert into t values 1,2,3,4,5,6,null,4,5,456,2,4,6,7,2144,44,2,-2,4"); 74 System.out.println(s.getUpdateCount() + " rows inserted"); 75 76 testAggregate(s, "select MAX(i) from t"); 80 testAggregate(s, "select MIN(i) from t"); 81 testAggregate(s, "select AVG(i) from t"); 82 testAggregate(s, "select COUNT(i) from t"); 83 testAggregate(s, "select COUNT(*) from t"); 84 85 s.execute("drop table t"); 86 s.close(); 87 conn.close(); 88 89 Thread.currentThread().setContextClassLoader(null); 90 } 91 92 95 private static void testAggregate(Statement s, String query) { 96 try { 97 ResultSet rs = s.executeQuery(query); 98 rs.next(); 99 System.out.println("query = " + rs.getInt(1)); 100 rs.close(); 101 } catch (SQLException e) { 102 System.out.println("FAIL " + e.getSQLState() + " " + e.getMessage()); 103 e.printStackTrace(System.out); 105 } 106 } 107 } 108 | Popular Tags |