| 3 | import java.sql.*; |
| 4 | |
| 5 | public class DBHelper { |
| 6 | private static Connection connection; |
| 7 | private static final String DATABASE = ReadProperty.getValue("mysql.db"); |
| 8 | |
| 9 | public static void saveTweet(String username, String mentionId, String mediaTweetId, String mediaUrl, String thumbnail, String mediaTweetUser, String mediaTweetText, String isSensitive) { |
| 10 | String sql = "INSERT INTO tweet_records(username, mention_id, media_tweet_id, media_url, thumbnail, media_tweet_user, media_tweet_text, is_sensitive) VALUES(?,?,?,?,?,?,?,?)"; |
| 11 | try { |
| 12 | connection = DriverManager.getConnection(DATABASE); |
| 13 | PreparedStatement ps = connection.prepareStatement(sql); |
| 14 | ps.setString(1, username); |
| 15 | ps.setString(2, mentionId); |
| 16 | ps.setString(3, mediaTweetId); |
| 17 | ps.setString(4, mediaUrl); |
| 18 | ps.setString(5, thumbnail); |
| 19 | ps.setString(6,mediaTweetUser); |
| 20 | ps.setString(7,mediaTweetText); |
| 21 | ps.setString(8,isSensitive); |
| 22 | ps.executeUpdate(); |
| 23 | connection.close(); |
| 24 | } catch (SQLException e) { |
| 25 | System.out.println(e.getMessage()); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | public static String getMention(String mentionId) { |
| 30 | StringBuilder mention = new StringBuilder(); |
| 31 | try { |
| 32 | connection = DriverManager.getConnection(DATABASE); |
| 33 | PreparedStatement ps = connection.prepareStatement("SELECT mention_id FROM tweet_records WHERE mention_id = ?"); |
| 34 | |
| 35 | ps.setString(1, mentionId); |
| 36 | |
| 37 | ResultSet rs = ps.executeQuery(); |
| 38 | while (rs.next()) { |
| 39 | mention.append(rs.getString("mention_id")); |
| 40 | } |
| 41 | connection.close(); |
| 42 | } catch (SQLException e) { |
| 43 | e.printStackTrace(); |
| 44 | } |
| 45 | return mention.toString(); |
| 46 | } |
| 47 | |
| 48 | } |