java在我插入数据时插入MySQL数据库的一行零
我正在将数据插入名为comp的MySQL表中。数据插入很好,但我在下一行中插入了一行零。你知道哪里不对吗
插入数据的代码:
String ret = ERROR;
Connection con = null;
try {
String URL = "jdbc:mysql://localhost/golfclub";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(URL, "root", "root");
PreparedStatement ps = con.prepareStatement("insert into comp values (?,?,?)");
ps.setString(1, getName());
ps.setInt(2, getHandicap());
ps.setInt(3, getTotalPoints());
ps.executeUpdate();
ret = SUCCESS;
} catch (Exception e) {
ret = ERROR;
} finally {
if (con != null) {
try {
con.close();
} catch (Exception e) {
}
}
}
return ret;
}
共 (0) 个答案