KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > jdbc > Finder


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

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 JavaDoc;
32 import java.sql.*;
33
34 /**
35  * Encapsulates finder select queries to the database
36  *
37  * @author stephan
38  * @version $Id: Finder.java 1256 2003-12-11 13:24:57Z leo $
39  */

40
41 public class Finder {
42   private PreparedStatement statement;
43   private String JavaDoc statementString;
44   private Connection connection;
45
46   public Finder(DataSource JavaDoc ds, String JavaDoc 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 JavaDoc 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