Hello i'm having trouble creating a MySQL "Event" through JAVA.JDBC. Here's the code:
public void skapaAuktionsEvent(String produktnamn, String slutdatum) throws SQLException{
String sql = "CREATE EVENT "+ produktnamn +" ON SCHEDULE AT '"+ slutdatum +"' DO UPDATE Auktion SET AvslutadAuktion = 1 WHERE produktnamn = "+ produktnamn;
System.out.println("Skapar event");
PreparedStatement stm = conn.prepareStatement("CREATE EVENT ? ON SCHEDULE AT ? DO UPDATE Auktion SET AvslutadAuktion = 1 WHERE produktnamn = ?",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
stm.setString(1, produktnamn);
stm.setString(2, slutdatum);
stm.setString(3, produktnamn);
PreparedStatement stm2 = conn.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
PreparedStatement stm3 = conn.prepareStatement("CREATE EVENT TestProdukt ON SCHEDULE AT '2015-02-15 15:15:00' DO UPDATE Auktion SET AvslutadAuktion = 1 WHERE produktnamn = TestProdukt",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
stm.execute();
System.out.println("Skapat Skiten");
stm.close();
}
So i've gotten both "stm2" and "stm3" works, but for some reason when i try and use stm which uses the .setString it all goes fubar.
I've tried removing the stm.setString(2, slutdatum) in case it was moaning about it wanting a Date formated value instead of string but that didnt help. It seems fail the moment the ? gets introduced. So i'm wondering what i'm doing wrong, and if there is another workaround except for using the stm2 variant since i doubt it's SQL safe.