1 22 23 import java.io.*; 24 import java.sql.*; 25 public class WwdUtils { 26 27 31 public static String getWishItem() { 32 BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); 33 String ans = ""; 34 try 35 { 36 while ( ans.length() == 0 ) { 37 System.out.println("Enter wish-list item (enter exit to end): "); 38 ans = br.readLine(); 39 if ( ans.length() == 0 ) 40 System.out.print("Nothing entered: "); 41 } 42 } catch (java.io.IOException e) { 43 System.out.println("Could not read response from stdin"); 44 } 45 return ans; 46 } 47 48 49 public static boolean wwdChk4Table (Connection conTst ) throws SQLException { 50 boolean chk = true; 51 boolean doCreate = false; 52 try { 53 Statement s = conTst.createStatement(); 54 s.execute("update WISH_LIST set ENTRY_DATE = CURRENT_TIMESTAMP, WISH_ITEM = 'TEST ENTRY' where 1=3"); 55 } catch (SQLException sqle) { 56 String theError = (sqle).getSQLState(); 57 59 if (theError.equals("42X05")) { return false; 61 } else if (theError.equals("42X14") || theError.equals("42821")) { 62 System.out.println("WwdChk4Table: Incorrect table definition. Drop table WISH_LIST and rerun this program"); 63 throw sqle; 64 } else { 65 System.out.println("WwdChk4Table: Unhandled SQLException" ); 66 throw sqle; 67 } 68 } 69 return true; 71 } 72 73 74 public static void main (String [] args) { 75 String answer; 77 do { 78 answer = getWishItem(); 79 if (! answer.equals("exit")) { 80 System.out.println ("You said: " + answer); 81 } 82 } while (! answer.equals("exit")) ; 83 } 84 85 } | Popular Tags |