KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > demos > scalability > jdbc > JDBCQueryConnection


1 package org.prevayler.demos.scalability.jdbc;
2
3 import org.prevayler.demos.scalability.*;
4 import java.sql.*;
5 import java.util.*;
6
7
8 // Contributions by Stefan Ortmanns.
9
class JDBCQueryConnection extends JDBCScalabilityConnection implements QueryConnection {
10
11     private final PreparedStatement selectStatement;
12
13
14     JDBCQueryConnection(Connection connection) {
15         super(connection);
16                                     
17         selectStatement = prepare("select ID,STRING1,BIGDECIMAL1,BIGDECIMAL2,DATE1,DATE2 from " + table() + " where NAME=?");
18     }
19
20
21     protected String JavaDoc table() {
22         return "QUERY_TEST";
23     }
24
25
26     public List queryByName(String JavaDoc name) {
27         ArrayList list = new ArrayList();
28         try {
29             selectStatement.setString(1, name);
30             ResultSet resultSet = selectStatement.executeQuery();
31
32             while (resultSet.next()) {
33                 list.add(new Record(resultSet.getLong(1), name, resultSet.getString(2), resultSet.getBigDecimal(3), resultSet.getBigDecimal(4), resultSet.getDate(5), resultSet.getDate(6)));
34             }
35
36         } catch (SQLException sqlex) {
37             dealWithSQLException(sqlex, "selecting record from " + table());
38         }
39
40         return list;
41     }
42 }
Popular Tags