2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 2001-2002, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
|
2 |
26 Feb 07 |
jari |
This software is provided "AS IS". TIGR makes no warranties, express |
2 |
26 Feb 07 |
jari |
or implied, including no representation or warranty with respect to |
2 |
26 Feb 07 |
jari |
the performance of the software and derivatives or their safety, |
2 |
26 Feb 07 |
jari |
effectiveness, or commercial viability. TIGR does not warrant the |
2 |
26 Feb 07 |
jari |
merchantability or fitness of the software and derivatives for any |
2 |
26 Feb 07 |
jari |
particular purpose, or that they may be exploited without infringing |
2 |
26 Feb 07 |
jari |
the copyrights, patent rights or property rights of others. TIGR shall |
2 |
26 Feb 07 |
jari |
not be liable for any claim, demand or action for any loss, harm, |
2 |
26 Feb 07 |
jari |
illness or other damage or injury arising from access to or use of the |
2 |
26 Feb 07 |
jari |
software or associated information, including without limitation any |
2 |
26 Feb 07 |
jari |
direct, indirect, incidental, exemplary, special or consequential |
2 |
26 Feb 07 |
jari |
damages. |
2 |
26 Feb 07 |
jari |
17 |
|
2 |
26 Feb 07 |
jari |
This software program may not be sold, leased, transferred, exported |
2 |
26 Feb 07 |
jari |
or otherwise disclaimed to anyone, in whole or in part, without the |
2 |
26 Feb 07 |
jari |
prior written consent of TIGR. |
2 |
26 Feb 07 |
jari |
21 |
*/ |
2 |
26 Feb 07 |
jari |
22 |
|
2 |
26 Feb 07 |
jari |
23 |
package org.tigr.util; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
import java.sql.Connection; |
2 |
26 Feb 07 |
jari |
26 |
import java.sql.ResultSet; |
2 |
26 Feb 07 |
jari |
27 |
import java.sql.ResultSetMetaData; |
2 |
26 Feb 07 |
jari |
28 |
import java.sql.SQLException; |
2 |
26 Feb 07 |
jari |
29 |
import java.sql.SQLWarning; |
2 |
26 Feb 07 |
jari |
30 |
import java.sql.Statement; |
2 |
26 Feb 07 |
jari |
31 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
public class Query { |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
private String queryString; |
2 |
26 Feb 07 |
jari |
36 |
private static final int SYBASE = 0; |
2 |
26 Feb 07 |
jari |
37 |
private static final int MYSQL = 1; |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
public Query(String queryString) { |
2 |
26 Feb 07 |
jari |
40 |
this.queryString = queryString; |
2 |
26 Feb 07 |
jari |
41 |
} |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
public Vector execute(Connection c) throws SQLException { |
2 |
26 Feb 07 |
jari |
//public Vector execute(Connection c) { |
2 |
26 Feb 07 |
jari |
45 |
return execute(c, true); |
2 |
26 Feb 07 |
jari |
46 |
} |
2 |
26 Feb 07 |
jari |
47 |
|
2 |
26 Feb 07 |
jari |
48 |
public Vector execute(Connection c, boolean returnHeadings) throws SQLException { |
2 |
26 Feb 07 |
jari |
//public Vector execute(Connection c, boolean returnHeadings) { |
2 |
26 Feb 07 |
jari |
50 |
Vector resultVector = null; |
2 |
26 Feb 07 |
jari |
51 |
Statement s = null; |
2 |
26 Feb 07 |
jari |
52 |
ResultSet rs = null; |
2 |
26 Feb 07 |
jari |
53 |
ResultSetMetaData rsmd = null; |
2 |
26 Feb 07 |
jari |
54 |
int columnCount = 0; |
2 |
26 Feb 07 |
jari |
55 |
String[] rowResults, columnLabels; |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
try { |
2 |
26 Feb 07 |
jari |
58 |
resultVector = new Vector(); |
2 |
26 Feb 07 |
jari |
59 |
s = c.createStatement(); |
2 |
26 Feb 07 |
jari |
60 |
boolean isQuery = s.execute(queryString); |
2 |
26 Feb 07 |
jari |
61 |
|
2 |
26 Feb 07 |
jari |
62 |
if (isQuery) { |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
rs = s.getResultSet(); |
2 |
26 Feb 07 |
jari |
65 |
rsmd = rs.getMetaData(); |
2 |
26 Feb 07 |
jari |
66 |
columnCount = rsmd.getColumnCount(); |
2 |
26 Feb 07 |
jari |
67 |
|
2 |
26 Feb 07 |
jari |
68 |
if (returnHeadings) { |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
columnLabels = new String[columnCount]; |
2 |
26 Feb 07 |
jari |
71 |
for (int i = 0; i < columnCount; i++) columnLabels[i] = rsmd.getColumnLabel(i + 1); |
2 |
26 Feb 07 |
jari |
72 |
if (columnLabels.length > 0) resultVector.addElement(columnLabels); |
2 |
26 Feb 07 |
jari |
73 |
} |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
while(rs.next()) { |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
rowResults = new String[columnCount]; |
2 |
26 Feb 07 |
jari |
78 |
for (int i = 0; i < columnCount; i++) { |
2 |
26 Feb 07 |
jari |
79 |
try { |
2 |
26 Feb 07 |
jari |
80 |
if (rs.getObject(i + 1).toString().trim() == null) { |
2 |
26 Feb 07 |
jari |
81 |
rowResults[i] = "null"; |
2 |
26 Feb 07 |
jari |
82 |
} else { |
2 |
26 Feb 07 |
jari |
83 |
rowResults[i] = rs.getObject(i + 1).toString().trim(); |
2 |
26 Feb 07 |
jari |
84 |
} |
2 |
26 Feb 07 |
jari |
85 |
} catch (NullPointerException npe) { |
2 |
26 Feb 07 |
jari |
86 |
rowResults[i] = "null"; |
2 |
26 Feb 07 |
jari |
87 |
} |
2 |
26 Feb 07 |
jari |
88 |
} |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
resultVector.addElement(rowResults); |
2 |
26 Feb 07 |
jari |
91 |
} |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
} else { |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
if (returnHeadings) resultVector.addElement(new String[]{"Rows affected"}); |
2 |
26 Feb 07 |
jari |
96 |
resultVector.addElement(new String[]{"" + s.getUpdateCount()}); |
2 |
26 Feb 07 |
jari |
97 |
} |
2 |
26 Feb 07 |
jari |
98 |
|
2 |
26 Feb 07 |
jari |
99 |
for (SQLWarning w = c.getWarnings(); w != null; w = w.getNextWarning()) { |
2 |
26 Feb 07 |
jari |
100 |
System.out.println("SQLWarning: " + w.getMessage() + ": " + w.getSQLState()); |
2 |
26 Feb 07 |
jari |
101 |
} |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
if (rs != null) rs.close(); |
2 |
26 Feb 07 |
jari |
104 |
s.close(); |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
106 |
} catch (SQLException sqle) { |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
throw sqle; |
2 |
26 Feb 07 |
jari |
109 |
} |
2 |
26 Feb 07 |
jari |
// we might not be able to use 'finally' here. If we use, the method will |
2 |
26 Feb 07 |
jari |
// ALWAYS return the updateCount and never throw the sqle. /JL |
2 |
26 Feb 07 |
jari |
/*} finally { |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
return resultVector; |
2 |
26 Feb 07 |
jari |
115 |
}*/ |
2 |
26 Feb 07 |
jari |
116 |
|
2 |
26 Feb 07 |
jari |
117 |
return resultVector; |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
public Vector executeQuery(Connection c) throws SQLException { |
2 |
26 Feb 07 |
jari |
//public Vector executeQuery(Connection c) { |
2 |
26 Feb 07 |
jari |
122 |
return executeQuery(c, true); |
2 |
26 Feb 07 |
jari |
123 |
} |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
125 |
public Vector executeQuery(Connection c, boolean returnHeadings) throws SQLException { |
2 |
26 Feb 07 |
jari |
//public Vector executeQuery(Connection c, boolean returnHeadings) { |
2 |
26 Feb 07 |
jari |
127 |
Vector resultVector = null; |
2 |
26 Feb 07 |
jari |
128 |
Statement s = null; |
2 |
26 Feb 07 |
jari |
129 |
ResultSet rs = null; |
2 |
26 Feb 07 |
jari |
130 |
ResultSetMetaData rsmd = null; |
2 |
26 Feb 07 |
jari |
131 |
int columnCount = 0; |
2 |
26 Feb 07 |
jari |
132 |
String[] rowResults, columnLabels; |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
try { |
2 |
26 Feb 07 |
jari |
135 |
resultVector = new Vector(); |
2 |
26 Feb 07 |
jari |
136 |
s = c.createStatement(); |
2 |
26 Feb 07 |
jari |
137 |
rs = s.executeQuery(queryString); |
2 |
26 Feb 07 |
jari |
138 |
rsmd = rs.getMetaData(); |
2 |
26 Feb 07 |
jari |
139 |
columnCount = rsmd.getColumnCount(); |
2 |
26 Feb 07 |
jari |
140 |
|
2 |
26 Feb 07 |
jari |
141 |
if (returnHeadings) { |
2 |
26 Feb 07 |
jari |
142 |
columnLabels = new String[columnCount]; |
2 |
26 Feb 07 |
jari |
143 |
for (int i = 0; i < columnCount; i++) columnLabels[i] = rsmd.getColumnLabel(i + 1); |
2 |
26 Feb 07 |
jari |
144 |
if (columnLabels.length > 0) resultVector.addElement(columnLabels); |
2 |
26 Feb 07 |
jari |
145 |
} |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
147 |
} catch (SQLException sqle) { |
2 |
26 Feb 07 |
jari |
148 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("SQLException: " + sqle); |
2 |
26 Feb 07 |
jari |
150 |
throw sqle; |
2 |
26 Feb 07 |
jari |
151 |
} |
2 |
26 Feb 07 |
jari |
152 |
|
2 |
26 Feb 07 |
jari |
153 |
try { |
2 |
26 Feb 07 |
jari |
154 |
while(rs.next()) { |
2 |
26 Feb 07 |
jari |
155 |
rowResults = new String[columnCount]; |
2 |
26 Feb 07 |
jari |
156 |
for (int i = 0; i < columnCount; i++) { |
2 |
26 Feb 07 |
jari |
157 |
try { |
2 |
26 Feb 07 |
jari |
158 |
if (rs.getObject(i + 1).toString().trim() == null) { |
2 |
26 Feb 07 |
jari |
159 |
rowResults[i] = "null"; |
2 |
26 Feb 07 |
jari |
160 |
} else { |
2 |
26 Feb 07 |
jari |
161 |
rowResults[i] = rs.getObject(i + 1).toString().trim(); |
2 |
26 Feb 07 |
jari |
162 |
} |
2 |
26 Feb 07 |
jari |
163 |
} catch (NullPointerException npe) { |
2 |
26 Feb 07 |
jari |
164 |
rowResults[i] = "null"; |
2 |
26 Feb 07 |
jari |
165 |
} |
2 |
26 Feb 07 |
jari |
166 |
} |
2 |
26 Feb 07 |
jari |
167 |
|
2 |
26 Feb 07 |
jari |
168 |
resultVector.addElement(rowResults); |
2 |
26 Feb 07 |
jari |
169 |
} |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
171 |
for (SQLWarning w = c.getWarnings(); w != null; w = w.getNextWarning()) { |
2 |
26 Feb 07 |
jari |
172 |
System.out.println("SQLWarning: " + w.getMessage() + ": " + w.getSQLState()); |
2 |
26 Feb 07 |
jari |
173 |
} |
2 |
26 Feb 07 |
jari |
174 |
|
2 |
26 Feb 07 |
jari |
175 |
if (rs != null) rs.close(); |
2 |
26 Feb 07 |
jari |
176 |
s.close(); |
2 |
26 Feb 07 |
jari |
177 |
|
2 |
26 Feb 07 |
jari |
178 |
} catch (SQLException sqle) { |
2 |
26 Feb 07 |
jari |
179 |
|
2 |
26 Feb 07 |
jari |
//System.out.println("SQLException: " + sqle); |
2 |
26 Feb 07 |
jari |
181 |
throw sqle; |
2 |
26 Feb 07 |
jari |
182 |
} |
2 |
26 Feb 07 |
jari |
// we might not be able to use 'finally' here. If we use, the method will |
2 |
26 Feb 07 |
jari |
// ALWAYS return the updateCount and never throw the sqle. -- JL |
2 |
26 Feb 07 |
jari |
185 |
|
2 |
26 Feb 07 |
jari |
/*} finally { |
2 |
26 Feb 07 |
jari |
187 |
|
2 |
26 Feb 07 |
jari |
return resultVector; |
2 |
26 Feb 07 |
jari |
189 |
}*/ |
2 |
26 Feb 07 |
jari |
190 |
|
2 |
26 Feb 07 |
jari |
191 |
return resultVector; |
2 |
26 Feb 07 |
jari |
192 |
} |
2 |
26 Feb 07 |
jari |
193 |
|
2 |
26 Feb 07 |
jari |
194 |
public int executeUpdate(Connection c) throws SQLException { |
2 |
26 Feb 07 |
jari |
//public int executeUpdate(Connection c) { |
2 |
26 Feb 07 |
jari |
196 |
int updateCount = 0; |
2 |
26 Feb 07 |
jari |
197 |
|
2 |
26 Feb 07 |
jari |
198 |
try { |
2 |
26 Feb 07 |
jari |
199 |
|
2 |
26 Feb 07 |
jari |
200 |
Statement s = c.createStatement(); |
2 |
26 Feb 07 |
jari |
201 |
updateCount = s.executeUpdate(queryString); |
2 |
26 Feb 07 |
jari |
202 |
for (SQLWarning w = c.getWarnings(); w != null; w = w.getNextWarning()) { |
2 |
26 Feb 07 |
jari |
203 |
System.out.println("SQLWarning: " + w.getMessage() + ": " + w.getSQLState()); |
2 |
26 Feb 07 |
jari |
204 |
} |
2 |
26 Feb 07 |
jari |
205 |
|
2 |
26 Feb 07 |
jari |
206 |
s.close(); |
2 |
26 Feb 07 |
jari |
207 |
|
2 |
26 Feb 07 |
jari |
208 |
} catch (SQLException sqle) { |
2 |
26 Feb 07 |
jari |
//System.out.println("SQLException: " + sqle); |
2 |
26 Feb 07 |
jari |
210 |
throw sqle; |
2 |
26 Feb 07 |
jari |
211 |
} |
2 |
26 Feb 07 |
jari |
// we might not be able to use 'finally' here. If we use, the method will |
2 |
26 Feb 07 |
jari |
// ALWAYS return the updateCount and never throw the sqle. -- JL |
2 |
26 Feb 07 |
jari |
/*} finally { |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
return updateCount; |
2 |
26 Feb 07 |
jari |
217 |
}*/ |
2 |
26 Feb 07 |
jari |
218 |
return updateCount; |
2 |
26 Feb 07 |
jari |
219 |
} |
2 |
26 Feb 07 |
jari |
220 |
|
2 |
26 Feb 07 |
jari |
221 |
public static Vector resultsToList(Vector results) { |
2 |
26 Feb 07 |
jari |
222 |
String[] rowResults; |
2 |
26 Feb 07 |
jari |
223 |
Vector resultVector = new Vector(); |
2 |
26 Feb 07 |
jari |
224 |
|
2 |
26 Feb 07 |
jari |
225 |
for (int i = 0; i < results.size(); i++) { |
2 |
26 Feb 07 |
jari |
226 |
rowResults = (String[]) results.elementAt(i); |
2 |
26 Feb 07 |
jari |
227 |
resultVector.addElement(rowResults[0]); |
2 |
26 Feb 07 |
jari |
228 |
} |
2 |
26 Feb 07 |
jari |
229 |
|
2 |
26 Feb 07 |
jari |
230 |
return resultVector; |
2 |
26 Feb 07 |
jari |
231 |
} |
2 |
26 Feb 07 |
jari |
232 |
|
2 |
26 Feb 07 |
jari |
233 |
public void setQueryStatement(String code){ |
2 |
26 Feb 07 |
jari |
234 |
queryString = code; |
2 |
26 Feb 07 |
jari |
235 |
} |
2 |
26 Feb 07 |
jari |
236 |
|
2 |
26 Feb 07 |
jari |
237 |
public static Vector resultsToVectors(Vector results) { |
2 |
26 Feb 07 |
jari |
238 |
String[] rowResults; |
2 |
26 Feb 07 |
jari |
239 |
Vector newResults; |
2 |
26 Feb 07 |
jari |
240 |
Vector resultVector = new Vector(); |
2 |
26 Feb 07 |
jari |
241 |
|
2 |
26 Feb 07 |
jari |
242 |
for (int i = 0; i < results.size(); i++) { |
2 |
26 Feb 07 |
jari |
243 |
newResults = new Vector(); |
2 |
26 Feb 07 |
jari |
244 |
rowResults = (String[]) results.elementAt(i); |
2 |
26 Feb 07 |
jari |
245 |
|
2 |
26 Feb 07 |
jari |
246 |
for (int j = 0; j < rowResults.length; j++) { |
2 |
26 Feb 07 |
jari |
247 |
newResults.addElement(rowResults[j]); |
2 |
26 Feb 07 |
jari |
248 |
} |
2 |
26 Feb 07 |
jari |
249 |
|
2 |
26 Feb 07 |
jari |
250 |
resultVector.addElement(newResults); |
2 |
26 Feb 07 |
jari |
251 |
} |
2 |
26 Feb 07 |
jari |
252 |
|
2 |
26 Feb 07 |
jari |
253 |
return resultVector; |
2 |
26 Feb 07 |
jari |
254 |
} |
2 |
26 Feb 07 |
jari |
255 |
|
2 |
26 Feb 07 |
jari |
256 |
public String toString() { |
2 |
26 Feb 07 |
jari |
257 |
return queryString; |
2 |
26 Feb 07 |
jari |
258 |
} |
2 |
26 Feb 07 |
jari |
259 |
|
2 |
26 Feb 07 |
jari |
260 |
/**************************************************************************** |
2 |
26 Feb 07 |
jari |
* <b>Description: </b> |
2 |
26 Feb 07 |
jari |
* starts a transaction for a DBMS. |
2 |
26 Feb 07 |
jari |
* <p><b>Parameters: </b> |
2 |
26 Feb 07 |
jari |
* <br> c -- the connection created with a DBMS. |
2 |
26 Feb 07 |
jari |
* <br> dbSys -- the DBMS to be handled; 0: Sybase; 1: MySql. |
2 |
26 Feb 07 |
jari |
266 |
***************************************************************************/ |
2 |
26 Feb 07 |
jari |
267 |
public static void beginTransaction(Connection c, int dbSys) throws SQLException { |
2 |
26 Feb 07 |
jari |
268 |
try { |
2 |
26 Feb 07 |
jari |
// Set the autocommit flag to false to enable transactions |
2 |
26 Feb 07 |
jari |
270 |
c.setAutoCommit(false); |
2 |
26 Feb 07 |
jari |
271 |
|
2 |
26 Feb 07 |
jari |
// Explicitly set the chained to off and begin transaction |
2 |
26 Feb 07 |
jari |
273 |
Statement stmt = c.createStatement(); |
2 |
26 Feb 07 |
jari |
274 |
if(dbSys == MYSQL){ |
2 |
26 Feb 07 |
jari |
275 |
stmt.execute("BEGIN"); |
2 |
26 Feb 07 |
jari |
276 |
} else if (dbSys == SYBASE){ |
2 |
26 Feb 07 |
jari |
277 |
stmt.execute("SET CHAINED OFF"); |
2 |
26 Feb 07 |
jari |
278 |
stmt.execute("BEGIN TRANSACTION"); |
2 |
26 Feb 07 |
jari |
279 |
} else { |
2 |
26 Feb 07 |
jari |
280 |
System.out.println("Error: No DBMS found."); |
2 |
26 Feb 07 |
jari |
281 |
} |
2 |
26 Feb 07 |
jari |
282 |
} catch (SQLException sqle) { |
2 |
26 Feb 07 |
jari |
283 |
|
2 |
26 Feb 07 |
jari |
284 |
throw sqle; |
2 |
26 Feb 07 |
jari |
285 |
} |
2 |
26 Feb 07 |
jari |
286 |
} |
2 |
26 Feb 07 |
jari |
287 |
|
2 |
26 Feb 07 |
jari |
288 |
/***************************************************************************** |
2 |
26 Feb 07 |
jari |
* endTransaction: transaction handling for DB |
2 |
26 Feb 07 |
jari |
290 |
***************************************************************************/ |
2 |
26 Feb 07 |
jari |
291 |
|
2 |
26 Feb 07 |
jari |
/* Complete transaction by executing a commit command and set the autocommit flag |
2 |
26 Feb 07 |
jari |
* back to true |
2 |
26 Feb 07 |
jari |
294 |
*/ |
2 |
26 Feb 07 |
jari |
295 |
public static void endTransaction(Connection c) throws SQLException { |
2 |
26 Feb 07 |
jari |
296 |
try { |
2 |
26 Feb 07 |
jari |
297 |
|
2 |
26 Feb 07 |
jari |
298 |
c.commit(); // Make the database changes permanent |
2 |
26 Feb 07 |
jari |
299 |
c.setAutoCommit(true); |
2 |
26 Feb 07 |
jari |
300 |
|
2 |
26 Feb 07 |
jari |
301 |
} catch (SQLException sqle) { |
2 |
26 Feb 07 |
jari |
302 |
|
2 |
26 Feb 07 |
jari |
303 |
throw sqle; |
2 |
26 Feb 07 |
jari |
304 |
} |
2 |
26 Feb 07 |
jari |
305 |
} |
2 |
26 Feb 07 |
jari |
306 |
|
2 |
26 Feb 07 |
jari |
307 |
/***************************************************************************** |
2 |
26 Feb 07 |
jari |
* abortTransaction: transaction handling for DB |
2 |
26 Feb 07 |
jari |
309 |
***************************************************************************/ |
2 |
26 Feb 07 |
jari |
310 |
|
2 |
26 Feb 07 |
jari |
/* Abort the transaction by rolling back changes made to the database and |
2 |
26 Feb 07 |
jari |
* set the autocommit flag back to true |
2 |
26 Feb 07 |
jari |
313 |
*/ |
2 |
26 Feb 07 |
jari |
314 |
public static void abortTransaction(Connection c) throws SQLException { |
2 |
26 Feb 07 |
jari |
315 |
|
2 |
26 Feb 07 |
jari |
316 |
try { |
2 |
26 Feb 07 |
jari |
317 |
|
2 |
26 Feb 07 |
jari |
318 |
c.rollback(); // Rollback database changes |
2 |
26 Feb 07 |
jari |
319 |
c.setAutoCommit(true); |
2 |
26 Feb 07 |
jari |
320 |
|
2 |
26 Feb 07 |
jari |
321 |
} catch (SQLException sqle) { |
2 |
26 Feb 07 |
jari |
322 |
|
2 |
26 Feb 07 |
jari |
323 |
throw sqle; |
2 |
26 Feb 07 |
jari |
324 |
} |
2 |
26 Feb 07 |
jari |
325 |
} |
2 |
26 Feb 07 |
jari |
326 |
} |