So I want to send a user to a mysql database with the columns: user, skill, time Now, I want it to be able to add more then one row for the same user but having different time and etc, how would I do this? Here's my code for sending it to the database:
public static boolean recentActivity(Player paramPlayer){
try {
Statement statement = con.createStatement();
ResultSet group = statement.executeQuery("SELECT * FROM recentactivity WHERE user = '"+ paramPlayer.getDisplayName() + "'");
if (!group.next() && !paramPlayer.levelTime.equals(""))
statement.execute("INSERT INTO `recentactivity`(`user`, `skill`, `time`) VALUES('"+ paramPlayer.getDisplayName() +"', '"+ paramPlayer.levelledSkill +"', '"+ paramPlayer.levelTime +"')");
} catch (Exception localException) {
return false;
}
return true;
} Then I have this to use it:
java.util.Date dt = new java.util.Date();
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
String currentTime = sdf.format(dt);
player.levelledSkill = skill;
player.levelTime = ""+currentTime+"";
Hiscores.recentActivity(player);
Any help with this?
Schema:
CREATE TABLE IF NOT EXISTS recentactivity (
user varchar(255) NOT NULL
, skill int(11) NOT NULL
, time varchar(255) NOT NULL
, PRIMARY KEY (user)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
recentactivity(uservarchar(255) NOT NULL,skillint(11) NOT NULL,timevarchar(255) NOT NULL, PRIMARY KEY (user) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;