1 21 22 package org.apache.derbyTesting.functionTests.util.StaticInitializers; 23 24 import java.sql.DriverManager ; 25 import java.sql.Statement ; 26 import java.sql.ResultSet ; 27 import java.sql.SQLException ; 28 29 30 public class DMLInStaticInitializer 31 { 32 33 34 public static int getANumber() 35 { 36 return 1; 37 } 38 39 static 40 { 41 42 doADMLStatement(); 43 } 44 45 private static void doADMLStatement() 46 { 47 ResultSet rs = null; 48 49 try 50 { 51 int value; 52 53 54 Statement s = DriverManager.getConnection( 55 "jdbc:default:connection").createStatement(); 56 57 58 rs = s.executeQuery("SELECT s FROM t1"); 59 60 if (rs.next()) 61 { 62 System.out.println("Value of t1.s is " + rs.getShort(1)); 63 } 64 } 65 catch (SQLException se) 66 { 67 System.out.println("Caught exception " + se); 68 se.printStackTrace(System.out); 69 } 70 finally 71 { 72 try 73 { 74 if (rs != null) 75 rs.close(); 76 } 77 catch (SQLException se) 78 { 79 System.out.println("Caught exception " + se); 80 se.printStackTrace(System.out); 81 } 82 } 83 } 84 } 85 | Popular Tags |