1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.util.jdbc;
17
18 import java.sql.Connection;
19 import java.sql.PreparedStatement;
20 import java.sql.SQLException;
21 import java.util.Vector;
22
23 /***
24 * @author Steve Viens (steve@viens.net)
25 */
26 public class DynamicQuery
27 {
28 /***
29 * Vector of all SQL values
30 */
31 private Vector values = null;
32 private StringBuffer sql = null;
33
34 /***
35 * default constructor
36 */
37 public DynamicQuery()
38 {
39 this.values = new Vector();
40 this.sql = new StringBuffer();
41 }
42
43 public DynamicQuery(String sql)
44 {
45 this.values = new Vector();
46 this.sql = new StringBuffer(sql);
47 }
48
49 public void append(String sql)
50 {
51 this.sql.append(sql);
52 }
53
54 public void addValue(Object obj)
55 {
56 this.values.addElement(obj);
57 }
58
59 public PreparedStatement buildPreparedStatement(Connection connection)
60 throws SQLException
61 {
62 PreparedStatement stmt = connection.prepareStatement(sql.toString());
63 for (int i=0; i<values.size(); i++)
64 stmt.setObject(i+1,values.elementAt(i));
65
66 return stmt;
67 }
68
69 public String toString()
70 {
71 StringBuffer buffer = new StringBuffer(sql.toString());
72 buffer.append("\n\n");
73
74 for (int i=0; i<values.size(); i++)
75 {
76 Object obj = values.elementAt(i);
77
78 buffer.append(i+1);
79 buffer.append("\t");
80 buffer.append(obj.getClass().getName());
81 buffer.append("\t");
82 buffer.append(obj.toString());
83 buffer.append("\n");
84 }
85
86 return buffer.toString();
87 }
88 }