private static void store( Map<Integer, UniqueEvent> data, java.sql.Connection conn, String table) { try { Statement stmt = conn.createStatement(); String q = "DROP TABLE IF EXISTS `" + table + "`;"; stmt.execute(q); q = "CREATE TABLE `" + table + "` (" + "`hash` INTEGER NOT NULL," + "`count` INTEGER UNSIGNED NOT NULL," + "`sum_confidence` DOUBLE UNSIGNED NOT NULL,"; for (String k : columns) q += "`" + k + "` VARCHAR(255), KEY `" + k + "` (`" + k + "`),"; q += "PRIMARY KEY (`hash`)) ENGINE = MyISAM;"; stmt.execute(q); q = "INSERT INTO " + table + " (hash,count,sum_confidence"; for (int i = 0; i < columns.length; i++) q += "," + columns[i]; q += ") VALUES (?,?,?" + Misc.replicateString(",?", columns.length) + ")"; PreparedStatement pstmt = conn.prepareStatement(q); for (Integer key : data.keySet()) { SQL.set(pstmt, 1, key); SQL.set(pstmt, 2, data.get(key).getCountDocs()); SQL.set(pstmt, 3, data.get(key).getSumConfidences()); int c = 4; for (String v : data.get(key).getData()) SQL.set(pstmt, c++, v); pstmt.execute(); } } catch (Exception e) { System.err.println(e); e.printStackTrace(); System.exit(-1); } }
private static void printSentences(PreparedStatement pstmt, int hash) { SQL.set(pstmt, 1, "" + hash); try { ResultSet rs = pstmt.executeQuery(); while (rs.next()) { System.out.print( "<li>" + rs.getString(2) + ": " + rs.getString(1).replace('\n', ' ') + "<br>"); } } catch (Exception e) { System.err.println(e); e.printStackTrace(); System.exit(0); } }
public void saveToDB(PreparedStatement pstmt) { try { SQL.set(pstmt, 1, xml); SQL.set(pstmt, 2, externalID != null ? externalID.getID() : null); SQL.set( pstmt, 3, externalID != null && externalID.getSource() != null ? externalID.getSource().toString().toLowerCase() : null); SQL.set(pstmt, 4, title); SQL.set(pstmt, 5, abs); SQL.set(pstmt, 6, body); SQL.set(pstmt, 7, rawContent); SQL.set(pstmt, 8, raw_type != null ? raw_type.toString().toLowerCase() : null); SQL.set(pstmt, 9, type != null ? type.toString().toLowerCase() : null); if (authors != null) SQL.set(pstmt, 10, Misc.implode(authors, "|")); else SQL.set(pstmt, 10, (String) null); SQL.set(pstmt, 11, year); SQL.set(pstmt, 12, journal != null ? journal.getISSN() : null); SQL.set(pstmt, 13, volume); SQL.set(pstmt, 14, issue); SQL.set(pstmt, 15, pages); pstmt.execute(); /*ResultSet rs = pstmt.getGeneratedKeys(); rs.first(); int id = rs.getInt(1); return id;*/ } catch (Exception e) { System.err.println(e); e.printStackTrace(); System.exit(-1); } }