From a9de546d1867c4a2f130cf55c208719eb6b27f54 Mon Sep 17 00:00:00 2001 From: Maurice Laveaux Date: Wed, 7 May 2014 14:02:23 +0200 Subject: Removed the extranous DBQuery and simpel property * InputReader reads from Scanner. --- src/database/QueryUtils.java | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/database/QueryUtils.java') diff --git a/src/database/QueryUtils.java b/src/database/QueryUtils.java index a120d1c..5b08655 100644 --- a/src/database/QueryUtils.java +++ b/src/database/QueryUtils.java @@ -1,5 +1,8 @@ package database; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import org.json.JSONException; import org.json.JSONObject; /** @@ -14,27 +17,32 @@ public class QueryUtils { * * @return A valid database query. */ - public static DBQuery insertProfile() { - String query = "INSERT INTO twitteruser (userid,displayname,timezone,tweetcount," + public static String insertProfile() { + return "INSERT INTO twitteruser (userid,displayname,timezone,tweetcount," + "followercount,followedcount,location) " + "SELECT ?, ?, ?, ?, ?, ?, ? " + "WHERE NOT EXISTS " + "(SELECT * FROM twitteruser WHERE userid= ? )"; - return new DBQuery(query); } - public static DBQuery insertTweet() { - String query = "INSERT INTO tweet (tweetid,createdat,favcount,retweetcount,text) " - + "SELECT ?, ?, ?, ?, ? WHERE NOT EXISTS (SELECT * FROM tweet WHERE tweetid= ? )"; - return new DBQuery(query); + public static String insertTweet() { + return "INSERT INTO tweet (tweetid,createdat,favcount,retweetcount,text) " + + "SELECT ?, ?, ?, ?, ? " + + "WHERE NOT EXISTS " + + "(SELECT * FROM tweet WHERE tweetid=? )"; + } + + public static String insetHash() { + return "INSERT INTO hashtag (tweetid, hashtag) " + + "SELECT ?, ? "; } - public static void setInsertParams(DBQuery query, JSONObject tweet) { - /*query.getPrepared().setLong(1, tweet.getLong("id")); - pst.setString(2, tweet.getString("created_at")); - pst.setLong(3, tweet.getLong("favorite_count")); - pst.setLong(4, tweet.getLong("retweet_count")); - pst.setString(5, tweet.getString("text")); - pst.setLong(6, tweet.getLong("id"));*/ + public static void setInsertParams(PreparedStatement statement, JSONObject tweet) throws JSONException, SQLException { + statement.setLong( 1, tweet.getLong( "id")); + statement.setString(2, tweet.getString("created_at")); + statement.setLong( 3, tweet.getLong( "favorite_count")); + statement.setLong( 4, tweet.getLong( "retweet_count")); + statement.setString(5, tweet.getString("text")); + statement.setLong( 6, tweet.getLong( "id")); } } -- cgit v1.2.1