apply modified suggstion from https://issues.apache.org/activemq/browse/AMQ-1191 - executeQuery conditional on statement metadata which works when statement does not return a result set like with derby which is used in the unit tests

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@787990 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2009-06-24 12:04:50 +00:00
parent 9a852b2a99
commit e2778fbf7d
2 changed files with 10 additions and 2 deletions

View File

@ -19,6 +19,8 @@ package org.apache.activemq.store.jdbc;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import javax.sql.DataSource;
@ -64,7 +66,13 @@ public class DefaultDatabaseLocker implements DatabaseLocker {
connection.setAutoCommit(false);
String sql = statements.getLockCreateStatement();
statement = connection.prepareStatement(sql);
if (statement.getMetaData() != null) {
ResultSet rs = statement.executeQuery();
// if not already locked the statement below blocks until lock acquired
rs.next();
} else {
statement.execute();
}
break;
} catch (Exception e) {
if (stopping) {

View File

@ -291,7 +291,7 @@ public class DefaultJDBCAdapter implements JDBCAdapter {
throw new SQLException("Failed to remove message");
}
} finally {
if (!this.batchStatments) {
if (!this.batchStatments && s != null) {
s.close();
}
}