1 5 package com.teamkonzept.lib; 6 7 import java.sql.*; 8 9 14 public class TKDBTemplate { 15 16 21 public static boolean prepareTemplate(ResultSet resultSet, TKTemplate template) 22 { 23 24 boolean boolResultSet=false; 25 TKHashtable result = getHashFromResult(resultSet); 26 27 if(result != null) 28 { 29 template.set( result ); 30 boolResultSet=true; 31 } 32 else { 33 boolResultSet=false; 34 } 35 return boolResultSet; 36 } 37 38 public static boolean prepareTemplate(TKDBResultRow row, TKTemplate template) 39 { 40 TKHashtable result = getHashFromResult(row); 41 if (result != null) 42 { 43 template.set( result ); 44 return true; 45 } 46 return false; 47 } 48 49 public static TKHashtable getHashFromResult(ResultSet resultSet) 50 { 51 TKHashtable result = null; 52 try 53 { 54 ResultSetMetaData rsmd = resultSet.getMetaData(); 57 58 int numCols = rsmd.getColumnCount(); 60 61 if(resultSet.next()) 62 { 63 result = new TKHashtable(); 64 for (int x=1; x<=numCols; x++) 65 { 66 String str = resultSet.getString(x); 67 if( str == null ) str = ""; 68 result.put( rsmd.getColumnLabel(x).toUpperCase(), str ); 69 } 70 } 71 } 72 catch (SQLException ex) { 73 TKDBLogger.logSQLException( ex ); 74 } 75 return result; 76 } 77 78 public static TKHashtable getHashFromResult(TKDBResultRow row) 79 { 80 if( !row.hasResult() ) return null; 81 82 int numCols = row.getColumnCount(); 83 TKHashtable result = new TKHashtable(); 84 85 for( int i=0; i<numCols; i++ ) { 86 result.put( row.getColumnLabel(i).toUpperCase(), row.getColumn( i ) ); 87 } 88 return result; 89 } 90 91 92 99 public static void prepareListTemplate( ResultSet resultSet, TKTemplate template, String listName ) 100 { 101 TKResultSetIterator iterator = new TKResultSetIterator( resultSet, template.getListIterator(), listName ); 102 template.setListIterator( iterator ); 103 } 104 105 112 public static void prepareListTemplate( TKDBResult result, TKTemplate template, String listName ) 113 { 114 TKDBResultIterator iterator = new TKDBResultIterator( result, template.getListIterator(), listName ); 115 template.setListIterator( iterator ); 116 } 117 118 } 120 | Popular Tags |