I'm working on a simple java project that uses JavaDB and MySQL to introduce the use of databases. I'm trying to write a method for updating the scores of a game in a database.
public void setTeamsScore(int matchNumber, int hScore, int vScore) throws SQLException
{
Statement stmt = connection.createStatement();
String sqlStatement = "UPDATE Matches " +
"SET HomeTeamScore = " + hScore +
" WHERE " +
"MatchNumber = " + matchNumber;
stmt.executeUpdate(sqlStatement);
sqlStatement = "UPDATE Matches " +
"SET VisitorTeamScore = " + vScore +
" WHERE " +
"MatchNumber = " + matchNumber;
stmt.executeUpdate(sqlStatement);
}
I get no errors at runtime, and when I check the return value of the update statement, it returns 1 (which if I understand correctly, means that 1 row was updated in the database). However, the database doesn't get updated at all and keeps the same values from before.
At first, I thought that maybe auto-commit wasn't working, so I tried turning auto-commit off and using connection.comit() but that didn't solve the problem either.
Any guidance would be much appreciated.