public static void main(String[] args) { MySqlImpl db = new MySqlImpl(); DBResultSet rs = db.retrieveResultSet( "select * from tbl_interactions where user_name = 'baolingfeng' and timestamp > '2015-03-20 17:56:54.411' order by timestamp limit 0,10"); for (Entry<String, String> e : rs.getcMeta().entrySet()) { System.out.println(e.getKey() + "/" + e.getValue()); } LowLevelInteraction u = InteractionUtil.fromDBRecord(rs.getRecords().get(0)); }
public DBResultSet retrieveResultSet(String sql) { Statement stmt = null; ResultSet rs = null; DBResultSet drs = new DBResultSet(); try { stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); rs = stmt.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { DBRecord r = new DBRecord(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { String columnName = rsmd.getColumnLabel(i); String columnType = rsmd.getColumnTypeName(i); drs.addColumn(columnName, columnType); if (columnType.contains("BLOB")) { try { BufferedImage img = ImageIO.read(rs.getBinaryStream(columnName)); r.add(columnName, img); } catch (Exception e) { r.add(columnName, rs.getBinaryStream(columnName)); } } else { r.add(columnName, rs.getObject(columnName)); } } drs.addRecord(r); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (stmt != null) stmt.close(); if (rs != null) rs.close(); } catch (Exception e) { e.printStackTrace(); } } return drs; }