Checking the database
I have not formalized it because I am currently the only user. In previous incarnations of the app I have incorporated data queries, with all sorts of filters and user customization, which no one has understood how to use.
My current ad hoc query code is as follows:
public class ItemdbQuery {
public static void main(String args[])
throws ClassNotFoundException, SQLException {
/**
* These are shared variable declarations
*/
Connection connect = null;
Statement stat = null;
/**
* This is the start of the main code.
*/
System.out.println("try connection");
try {
// Load database driver
Class.forName("org.apache.derby.jdbc.ClientDriver");
// Make connection
String connn = "jdbc:derby://192.168.2.2:1527/dbAMJ";
connect = DriverManager.getConnection( connn );
stat = connect.createStatement();
System.out.println("connection succeeds");
} catch(Exception ex) {
System.out.println("connection fails");
System.err.println("SQLException: " + ex.getMessage());
}
// Execute a query
System.out.println("try query");
try {
String aquery = "SELECT * FROM Items";
ResultSet resultSet = stat.executeQuery(aquery);
// Display results
while(resultSet.next()) {
System.out.println(resultSet.getString(1) + " " +
resultSet.getString(2) + " " +
resultSet.getString(3) + " " +
resultSet.getString(4) + " " +
resultSet.getString(5) + " " +
resultSet.getString(6));
}
resultSet.close();
stat.close();
System.out.println("query succeeds");
} catch(Exception ex) {
System.out.println("query fails");
System.err.println("SQLException: " + ex.getMessage());
} finally {
// Close connection
if (connect!= null) {
try {
connect.close();
System.out.println("disconnection succeeds");
} catch (SQLException sqlEx) {
System.out.println("disconnection fails");
}
}
}
}
}
This code differs from that used for my financial transaction query in that the database is hosted remotely, so the derby "Clientdriver" was used, and the connection string included the local IP address of my server.
A sample of the data output is given below:
23 1247061594801 1 3 + 2 = 1 8.683068
24 1247061594801 1 5 + 3 = 1 36.518562
25 1247061594801 1 2 + 5 = 1 39.164494
The fields are essentially: an index, a datestamp, an operation code, an item, the raw score for the item, and the scoring rate. This can be sucked into a spreadsheet or GUI database for further analysis.
Comments