// there should be only two columns in the map
// 0 = query
// 1 = DiscreteOrGradientColor color assigned to result set rows
Vector row = (Vector) dataVector.get(k);
String q = (String) row.get(0);
DiscreteOrGradientColor col = (DiscreteOrGradientColor) row.get(1);
// try the query
try {
if (sql == null) {
JOptionPane.showMessageDialog(colorQueryPanel, "Please make a new connection, this"
+ " one is dead\nor not providing relevant data...");
} else {
Statement sqlstatement = sql.createStatement(
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
rs = sqlstatement.executeQuery(q);
}
} catch (SQLException e1) {
e1.printStackTrace();
// there was a problem with the query
int answer = JOptionPane.showConfirmDialog(
null,
"The query on row "
+ k
+ " failed with these warnings:\n"
+ e1.getMessage()
+ "\n Would you like me to continue trying the rest?",
"Query Error", JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.OK_OPTION) {
// skip the rest of the for loop and
// go immediately to the next query
continue;
} else {
cancel();
return null;
}
}
// rs is set to null if the user cancels,
// in which case we'll cancel and return null
if (null == rs) {
cancel();
return null;
}
// make sure we can map from ResultSet columns to vis dimensions
try {
/*
* In order to map every row of a ResultSet to a pixel in an
* image, we either need the DataInfo.computedPrimaryKey _or_
* DataInfo.parameterNames to be specified as columns in the
* ResultSet. We make sure that is the case here. TODO: it would
* be great if you could make this check using the String query,
* before the query is actually executed. I just didn't feel
* like trying to figure out the parsing right now.
*/
ResultSetMetaData meta = rs.getMetaData();
int[] indices = ResultSetParser.getIndices(meta, dataInfo);
if (!ResultSetParser.checkIndices(indices)) {
int answer = JOptionPane.showConfirmDialog(
null,
"The query must include either a primary key that is computed \n"
+ "from the parameters or it must include those parameters \n"
+ "themselves in the select statement. For the query on row \n"
+ k
+ " this is not the case. \n"
+ "Would you like me to continue trying the rest of the queries?",
"Qeury Error", JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.OK_OPTION) {
// skip the rest of the for loop and
// go immediately to the next query
continue;
} else {
cancel();
return null;
}
}
if (col.isDiscreteOrGradient()) {
rgb = processResultSetForGradientColor(sql, q, rs, col, rgb);
} else {
rgb = processResultSetForDiscreteColor(rs,
col.getColorOne(), rgb);
}
/*
* TODO: if you have one query that has bad syntax, and it asks
* if you want to continue with the other queries, and you click
* yes, then it fails here because you're out of the for loop? -