try {
connection = _pool.getConnection();
Statement statement = connection.createStatement();
JdbcQueryResult result = new JdbcQueryResult();
if (statement.execute(sql)) {
ArrayList<String[]> rows = new ArrayList<String[]>();
ResultSet resultSet = statement.getResultSet();
ResultSetMetaData metadata = resultSet.getMetaData();
int columnCount = metadata.getColumnCount();
// add column names
String []names = new String[columnCount];
for (int i = 0; i < columnCount; i++)
names[i] = metadata.getColumnName(i + 1);
result.setRowNames(names);
// add results
while (resultSet.next()) {
String []row = new String[columnCount];
for (int i = 0; i < columnCount; i++) {
try {
row[i] = resultSet.getString(i + 1);
}
catch (SQLException e) {
// MySQL zero date conversion issue
if (e.getMessage().startsWith("Cannot convert value '0000-00-00"))
row[i] = "0000-00-00 00:00:00";
else
throw e;
}
}
rows.add(row);
}
String [][]rowsArray = new String[rows.size()][];
rows.toArray(rowsArray);
result.setResultData(rowsArray);
return result;
}
return null;