Revision 9491
Added by Jing Tao almost 9 years ago
src/edu/ucsb/nceas/metacat/AccessionNumber.java | ||
---|---|---|
174 | 174 |
boolean hasAccNumber = false; |
175 | 175 |
DBConnection conn = null; |
176 | 176 |
int serialNumber = -1; |
177 |
PreparedStatement pstmt = null; |
|
178 |
ResultSet rs = null; |
|
177 | 179 |
|
178 | 180 |
try { |
179 |
PreparedStatement pstmt = null; |
|
181 |
|
|
180 | 182 |
//check out DBConnection |
181 | 183 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberUsed"); |
182 | 184 |
serialNumber=conn.getCheckOutSerialNumber(); |
... | ... | |
189 | 191 |
pstmt.setString(1,accNumber); |
190 | 192 |
pstmt.setString(2,accNumber); |
191 | 193 |
pstmt.execute(); |
192 |
ResultSet rs = pstmt.getResultSet();
|
|
194 |
rs = pstmt.getResultSet(); |
|
193 | 195 |
hasAccNumber = rs.next(); |
194 |
pstmt.close(); |
|
196 |
//pstmt.close();
|
|
195 | 197 |
|
196 | 198 |
} catch (SQLException e) { |
197 | 199 |
throw new SQLException |
... | ... | |
199 | 201 |
} |
200 | 202 |
finally |
201 | 203 |
{ |
202 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
204 |
try { |
|
205 |
if(rs != null) { |
|
206 |
rs.close(); |
|
207 |
} |
|
208 |
if(pstmt != null) { |
|
209 |
pstmt.close(); |
|
210 |
} |
|
211 |
} finally { |
|
212 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
213 |
} |
|
214 |
|
|
203 | 215 |
} |
204 | 216 |
|
205 | 217 |
return hasAccNumber; |
... | ... | |
213 | 225 |
boolean hasCurrentAccNumber = false; |
214 | 226 |
DBConnection conn = null; |
215 | 227 |
int serialNumber = -1; |
216 |
|
|
228 |
ResultSet rs = null; |
|
229 |
PreparedStatement pstmt = null; |
|
217 | 230 |
try { |
218 |
PreparedStatement pstmt = null; |
|
231 |
|
|
219 | 232 |
//check out DBConnection |
220 | 233 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.accNumberIsCurre"); |
221 | 234 |
serialNumber=conn.getCheckOutSerialNumber(); |
... | ... | |
224 | 237 |
"WHERE docid = ?"); |
225 | 238 |
pstmt.setString(1, accNumber); |
226 | 239 |
pstmt.execute(); |
227 |
ResultSet rs = pstmt.getResultSet();
|
|
240 |
rs = pstmt.getResultSet(); |
|
228 | 241 |
hasCurrentAccNumber = rs.next(); |
229 | 242 |
if(!hasCurrentAccNumber) |
230 | 243 |
{ |
... | ... | |
237 | 250 |
rs = pstmt.getResultSet(); |
238 | 251 |
hasCurrentAccNumber = rs.next(); |
239 | 252 |
} |
240 |
pstmt.close(); |
|
253 |
//pstmt.close();
|
|
241 | 254 |
|
242 | 255 |
} catch (SQLException e) { |
243 | 256 |
throw new SQLException( |
... | ... | |
246 | 259 |
} |
247 | 260 |
finally |
248 | 261 |
{ |
249 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
262 |
|
|
263 |
try { |
|
264 |
if(rs != null) { |
|
265 |
rs.close(); |
|
266 |
} |
|
267 |
if(pstmt != null) { |
|
268 |
pstmt.close(); |
|
269 |
} |
|
270 |
} finally { |
|
271 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
272 |
} |
|
273 |
|
|
250 | 274 |
} |
251 | 275 |
|
252 | 276 |
return hasCurrentAccNumber; |
... | ... | |
258 | 282 |
String rev = ""; |
259 | 283 |
DBConnection conn = null; |
260 | 284 |
int serialNumber = -1; |
261 |
|
|
285 |
PreparedStatement pstmt = null; |
|
286 |
ResultSet rs = null; |
|
262 | 287 |
try { |
263 |
PreparedStatement pstmt = null; |
|
288 |
|
|
264 | 289 |
//check out DBConnection |
265 | 290 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevision"); |
266 | 291 |
serialNumber=conn.getCheckOutSerialNumber(); |
... | ... | |
269 | 294 |
pstmt.setString(1, docid); |
270 | 295 |
pstmt.execute(); |
271 | 296 |
|
272 |
ResultSet rs = pstmt.getResultSet();
|
|
297 |
rs = pstmt.getResultSet(); |
|
273 | 298 |
boolean hasRow = rs.next(); |
274 | 299 |
rev = rs.getString(1); |
275 |
pstmt.close(); |
|
300 |
//pstmt.close();
|
|
276 | 301 |
|
277 | 302 |
} catch (SQLException e) { |
278 | 303 |
throw new SQLException( |
... | ... | |
280 | 305 |
} |
281 | 306 |
finally |
282 | 307 |
{ |
283 |
DBConnectionPool.returnDBConnection(conn,serialNumber); |
|
308 |
try { |
|
309 |
if(rs != null) { |
|
310 |
rs.close(); |
|
311 |
} |
|
312 |
if(pstmt != null) { |
|
313 |
pstmt.close(); |
|
314 |
} |
|
315 |
} finally { |
|
316 |
DBConnectionPool.returnDBConnection(conn,serialNumber); |
|
317 |
} |
|
318 |
|
|
284 | 319 |
} |
285 | 320 |
|
286 | 321 |
return rev; |
... | ... | |
296 | 331 |
int rev = 1; |
297 | 332 |
DBConnection conn =null; |
298 | 333 |
int serialNumber = -1; |
299 |
|
|
334 |
PreparedStatement pStmt = null; |
|
335 |
ResultSet rs = null; |
|
300 | 336 |
try { |
301 |
PreparedStatement pStmt = null; |
|
337 |
|
|
302 | 338 |
//check out DBConnection |
303 | 339 |
conn=DBConnectionPool.getDBConnection("AccessionNumber.getLastRevisionN"); |
304 | 340 |
serialNumber=conn.getCheckOutSerialNumber(); |
... | ... | |
308 | 344 |
pStmt.setString(1, docId); |
309 | 345 |
pStmt.execute(); |
310 | 346 |
|
311 |
ResultSet rs = pStmt.getResultSet();
|
|
347 |
rs = pStmt.getResultSet(); |
|
312 | 348 |
boolean hasRow = rs.next(); |
313 | 349 |
if(hasRow) |
314 | 350 |
{ |
315 | 351 |
rev = rs.getInt(1); |
316 | 352 |
} |
317 |
pStmt.close(); |
|
353 |
//pStmt.close();
|
|
318 | 354 |
|
319 | 355 |
} catch (SQLException e) { |
320 | 356 |
throw new SQLException( |
... | ... | |
322 | 358 |
} |
323 | 359 |
finally |
324 | 360 |
{ |
325 |
DBConnectionPool.returnDBConnection(conn,serialNumber); |
|
361 |
try { |
|
362 |
if(rs != null) { |
|
363 |
rs.close(); |
|
364 |
} |
|
365 |
if(pStmt != null) { |
|
366 |
pStmt.close(); |
|
367 |
} |
|
368 |
} finally { |
|
369 |
DBConnectionPool.returnDBConnection(conn,serialNumber); |
|
370 |
} |
|
371 |
|
|
326 | 372 |
} |
327 | 373 |
return rev; |
328 | 374 |
} |
Also available in: Unified diff
Close the result and connection in the finally clause to make sure they being closed.