【发布时间】:2013-01-15 11:39:45
【问题描述】:
这是我的代码:
public void submitReply(ActionEvent e) {
String replyBy = userName;
String reply = jTextArea_reply.getText();
if (reply.equals("")) {
JOptionPane.showMessageDialog(null, "Comment cannot leave blank");
} else {
eForumTopics comment = new eForumTopics(replyBy, reply);
if (comment.createComment() == true) {
JOptionPane
.showMessageDialog(null,
"Reply submitreted successfully. You will be redirect to main page.");
SetUpJTableComment();
public void SetUpJTableComment() {
// Get jTable model
DefaultTableModel tableModel1 = (DefaultTableModel) jTableComment
.getModel();
// Store column data into Array (3 columns)
String[] data = new String[3];
// Set Up Database Source
db.setUp("IT Innovation Project");
String sql = "Select reply_content,reply_by from forumReplies WHERE reply_topic = "
+ topicId + "";
ResultSet resultSet = null;
// Call readRequest to get the result
resultSet = db.readRequest(sql);
try {
while (resultSet.next()) {
data[0] = resultSet.getString("reply_content");
data[1] = resultSet.getString("reply_by");
// Add data to table model
tableModel1.addRow(data);
}
resultSet.close();
} catch (Exception e) {
System.out.println(e);
}
// add tablemodel to jtable
}
问题是每当用户发布新回复时,现有帖子都会重新添加在一起。我尝试只将评论框中的较新回复添加到 jTable 中,而不是继续使用更新的回复重新添加现有帖子。我应该用什么?一个for循环?提前致谢。
【问题讨论】:
-
与上一个问题一样的次优(您被告知无需再次设置模型)代码 sn-p - 开始挖掘真正的问题如何?
-
另外:学习 java 命名约定并遵守它们 - 现在
-
我已经编辑过了,我应该怎么做才能防止现有帖子继续重新添加?
-
检查查询 - 它是否在每次调用中返回其他内容?
-
您指的是哪个查询?是sql语句吗?如果是这样,则 sql 语句将返回基于 topicId 的所有回复。然后我再次调用该方法,以便继续执行 sql 语句。但是如何过滤呢?
标签: swing jtable defaulttablemodel