1 25 26 package org.snipsnap.jdbc; 27 28 import org.radeox.util.logging.Logger; 29 import org.snipsnap.util.ConnectionManager; 30 31 import javax.sql.DataSource ; 32 import java.sql.*; 33 34 40 41 public class Finder { 42 private PreparedStatement statement; 43 private String statementString; 44 private Connection connection; 45 46 public Finder(DataSource ds, String statement) { 47 try { 48 this.connection = ds.getConnection(); 49 this.statementString = statement; 50 this.statement = this.connection.prepareStatement(statement); 51 } catch (SQLException e) { 52 Logger.warn("Unable to prepare statement: " + statementString); 53 } 54 } 55 56 public Finder setDate(int column, Timestamp date) { 57 try { 58 statement.setTimestamp(column, date); 59 } catch (SQLException e) { 60 Logger.warn("Unable to set Timestamp value: " + statementString); 61 } 62 return this; 63 } 64 65 public Finder setString(int column, String value) { 66 try { 67 statement.setString(column, value); 68 } catch (SQLException e) { 69 Logger.warn("Unable to set String value: " + statementString); 70 } 71 return this; 72 } 73 74 public ResultSet execute() { 75 try { 76 return statement.executeQuery(); 77 } catch (SQLException e) { 78 Logger.warn("Unable to execute Query "+statementString); 79 return null; 80 } 81 } 82 83 public void close() { 84 ConnectionManager.close(statement); 85 ConnectionManager.close(connection); 86 } 87 } 88 | Popular Tags |