我尝试为论坛线程做类似的计数器。这是我的代码:
点击喜欢按钮时,它会将值插入数据库。
public void submitLike(ActionEvent e) {
int count = 0;
int newCount = count + 1;
eForumLikeDislike amount = new eForumLikeDislike(userName,topicId,newCount);
amount.likeCounter();
}
SQL statement
我在点击时插入的那个。
public void SetUpLikeAmount() {
int likes = 0;
ArrayList <Integer> likeArray = new ArrayList <Integer>();
for (int count = 0; count < likeArray.size();count++){
// Set Up Database Source
db.setUp("IT Innovation Project");
String sql = "Select likeDislike_likes from forumLikeDislike WHERE topic_id = "
+ topicId + "";
ResultSet resultSet = null;
// Call readRequest to get the result
resultSet = db.readRequest(sql);
try {
while (resultSet.next()) {
likeArray.add(Integer.parseInt(resultSet.getString("likeDislike_likes")));
}
resultSet.close();
} catch (Exception e) {
System.out.println(e);
}
likes += likeArray.get(count);
}
jLabel_like.setText(Integer.toString(likes));
}
我尝试显示某个线程的总喜欢的方法。
public void SetUpLikeAmount() {
int likes = 0;
ArrayList <Integer> likeArray = new ArrayList <Integer>();
for (int count = 0; count < likeArray.size();count++) {
// Set Up Database Source
db.setUp("IT Innovation Project");
String sql = "Select likeDislike_likes from forumLikeDislike WHERE topic_id = "
+ topicId + "";
ResultSet resultSet = null;
// Call readRequest to get the result
resultSet = db.readRequest(sql);
try {
while (resultSet.next()) {
likes = Integer.parseInt(resultSet.getString("likeDislike_likes"));
likes += likeArray.get(count);
}
resultSet.close();
} catch (Exception e) {
System.out.println(e);
}
}
jLabel_like.setText(Integer.toString(likes));
}
但是,金额一直退回给我0。有什么问题吗?我该如何解决?
提前致谢。