private void printResults() throws SqlJetException {
db.beginTransaction(SqlJetTransactionMode.WRITE);
try {
ISqlJetTable table = db.getTable("answers");
final ISqlJetCursor cursor = table.lookup("login", login.getLogin());
TableModel dataModel = new AbstractTableModel() {
String[][] mas = new String[(int) cursor.getRowCount()][2];
{
makeMas();
}
public int getRowCount() {
try {
return (int) cursor.getRowCount();
} catch (SqlJetException e) {
e.printStackTrace();
}
return 0;
}
public int getColumnCount() {
return 2;
}
public String getColumnName(int i) {
return i == 0 ? "Number of question" : "Result";
}
public void makeMas() throws SqlJetException {
int i = 0;
if (!cursor.eof()) {
do {
mas[i][0] = cursor.getString("question");
mas[i][1] = cursor.getString("answer").equals("1") ? "Correct" : "Incorrect";
i++;
} while (cursor.next());
}
}
public Object getValueAt(int row, int col) {
return mas[row][col];
}
};
results.getResultTable().setModel(dataModel);
results.getResultsHeader().getColumnModel().addColumn(new TableColumn());
results.getResultsHeader().getColumnModel().addColumn(new TableColumn());
results.getResultsHeader().getColumnModel().getColumn(0).setHeaderValue("Number of question");
results.getResultsHeader().getColumnModel().getColumn(1).setHeaderValue("Your answer is");
results.getResultsHeader().getColumnModel().getColumn(0).setWidth(300);
results.getResultsHeader().getColumnModel().getColumn(1).setWidth(300);
cursor.close();
} finally {
db.commit();
}
}