}
return contents.toString();
}
public void testPrepareStatement() {
DatabaseWriter db = new DatabaseWriter(cluster);
Date today = new Date();
long current = today.getTime();
Timestamp timestamp = new Timestamp(current);
String hostname="chukwa.example.org";
String query = "insert into [system_metrics] set timestamp='"+timestamp.toString()+"', host='"+hostname+"', cpu_user_pcnt=100;";
Macro mp = new Macro(current, current, query);
query = mp.toString();
try {
db.execute(query);
query = "select timestamp,host,cpu_user_pcnt from [system_metrics] where timestamp=? and host=? and cpu_user_pcnt=?;";
mp = new Macro(current, current, query);
query = mp.toString();
ArrayList<Object> parms = new ArrayList<Object>();
parms.add(current);
parms.add(hostname);
parms.add(100);
ResultSet rs = db.query(query, parms);
while(rs.next()) {
assertTrue(hostname.intern()==rs.getString(2).intern());
assertTrue(100==rs.getInt(3));
}
db.close();
} catch(SQLException ex) {
fail("Fail to run SQL statement:"+ExceptionUtil.getStackTrace(ex));
}
}