Hello! Im trying to write some method, which will add a new record to date base.
Code:
public void insertToPlayList() {
try {
connecting();
stat6 = Connection.createStatement();
stat6.executeUpdate("INSERT INTO odtwarzane VALUES('','2','4','2','2015-10-10','10:10')");
connecting();
} catch (SQLException Exception) {
JOptionPane.showMessageDialog(null, "Wystąpił problem z dodaniem rekordu.", "Błąd", JOptionPane.ERROR_MESSAGE);
}
}
Originally, this method is getting 5 paramenters, but for fixing problem i removed it.
public void insertToPlayList(int filmId, int cinemaId, int priceId, String date, String time) {
try {
connecting();
stat6 = Connection.createStatement();
String str = ("INSERT INTO odtwarzane (id_of, id_filmu, id_kina, id_ceny, data, godzina) VALUES (," + filmId + ", " + cinemaId + ", " + priceId + ", '" + date + "', '" + time + "');");
stat6.executeUpdate(str);
connecting();
} catch (SQLException Exception) {
JOptionPane.showMessageDialog(null, "Wystąpił problem z dodaniem rekordu.", "Błąd", JOptionPane.ERROR_MESSAGE);
}
}
I checked on PhpMyAdmin, and statment was worked
INSERT INTO odtwarzane VALUES('','2','4','2','2015-10-10','10:10');
Anyway, program is throwing SQLException, and i dont know how to fix it.
What I have tried:
I tried to change statement or code in many ways, and i was looking for some solution in the Internet, but i didnt find it.