Запрос на обновление и запрос на удаление не работают, только выбор и вставка.
public static void updateQuery(String date) throws SQLException{
String query = "update parks set flag=? where nick=? and day=?";
PreparedStatement ps = mia.connect.prepareStatement(query);
ps.setString(1,"y");
ps.setString(2,user.getNickname());
ps.setDate(3, Date.valueOf(date));
ps.executeUpdate();
}
public static void deleteQuery(String date) throws SQLException{
String query = "delete from parks where nick=? and day=?";
PreparedStatement ps = mia.connect.prepareStatement(query);
ps.setString(1,user.getNickname());
ps.setDate(2, Date.valueOf(date));
ps.execute();
}
public static void insert(int id_park,int weightTrip,LocalDate date,int during,int time) throws SQLException{
// take the price
int fullPrice = calculatePrice(id_park);
frullPrice = fullPrice*during;
String query = "insert into parks(numberID,nick,idpark,price,during,time,day,weithtrip,flag) " +
"values (?,?,?,?,?,?,?,?,?)";
PreparedStatement ps = mia.connect.prepareStatement(query);
Random rand = new Random();
int value = 0;
value = rand.nextInt((999 - 1) + 1) + 1;
ps.setInt(1,value);
ps.setString(2,user.getNickname());
ps.setInt(3,id_park);
ps.setInt(4,fullPrice);
ps.setInt(5,during);
ps.setInt(6,time);
ps.setDate(7, Date.valueOf(date));
ps.setInt(8,weightTrip);
ps.setString(9,"n");
ps.execute();
}
это actionListener на кнопке, которая вызывает процедуру.(удаление такое же, но вместо 'DBOperations.updateQuery' есть 'DBOperation.deleteQuery')
submitButton.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
DBOperations.updateQuery(dateOfThePayment);
JOptionPane.showMessageDialog(this,"thanks !");
} catch (SQLException e2) {
e2.printStackTrace();
}
}
});
this is the table :
create table parks (
numberID integer not null,
nick varchar(10) not null,
idpark int not null,
price int,
during int,
time int,
day date,
weighttrip int,
flag varchar(1),
)
Эти запросы не дают мне никакой ошибки.Проблема в том, что они не делают свою работу.Если я выполню тот же запрос в командной строке, они будут работать хорошо.