如何将jtable单元格值编辑/更新到数据库中

时间:2016-03-19 15:03:26

标签: java

我正在尝试编辑和更新jtable单元格,如下面的代码所示。我的问题是,当更新所有其他行时,单行获得相同的值。我的意思是只更新了一行,所有其他行都是重复的。任何人都可以帮助一个好的方法。感谢

zodiacMap1.put("Taurus", "April 20 - May 20");
zodiacMap1.put("Libra", "September 23 - October 22");
zodiacMap1.put("Scorpio", "October 23 - November 21");
zodiacMap1.put("Aquarius", "January 20 - February 18");

zodiacMap1.put("Aries", "March 21 - April 19");
zodiacMap1.put("Gemini", "May 21 - June 20");
zodiacMap1.put("Cancer", "June 21 - July 22");
zodiacMap1.put("Leo", "July 23 - August 22");
zodiacMap1.put("Virgo", "August 23 - September 22");
zodiacMap1.put("Capricorn", "November 22 - December 21");
zodiacMap1.put("Pisces", "February 19 - March 20");

1 个答案:

答案 0 :(得分:0)

您的sql语句不包含where子句,因此数据库表中的所有行都会针对swing-table-rows的每次迭代进行更新,最后,所有数据库行都将具有来自最后摆桌子。

(并且,使用pst.setParameter(http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html)并且不要将sql混合到gui-code中。)