mySql - PreparedStatement: Batch()

37
March 15, 2019, at 7:10 PM

Hej there,

****SOLVED*****

I have an issue with this preparestatement batch()

The method get processed, - no errors... But no data in the table. Been trying to solve this by reading a whole lot, but I just cant fix it. ( I am totally new to batch(), maye I got it all wrong).

  • I hope there is a person with a bit more experience than me, that maybe would give me a hint. - thanks

private MovieEvent addMovieEventSeatsToTable(MovieEvent event, List seats, int currentMovieEventId) {

    DataSource ds = Jdbc.getDataSource();
    String tableId = "movieEvent" + String.valueOf(currentMovieEventId);
    String SQL_EVENT_SEATS = "INSERT INTO " + tableId + "(seatId, isReserved) " + "VALUES(?,?) ";
    try (Connection connection = ds.getConnection();
         PreparedStatement preparedStatement = connection.prepareStatement(SQL_EVENT_SEATS);) {
        int cnt = 0;
        // Fill table with seats:
        for (int i = 0; i < seats.size(); i++) {
            String seatId = seats.get(i).getSeatId();
            boolean isReserved = seats.get(i).isReserved();
            preparedStatement.setString(1, seatId);
            preparedStatement.setBoolean(2, isReserved);
            preparedStatement.addBatch();
            cnt++;
            // More than 100 in a batch - execute
            if (cnt % 100 == 0 || cnt == seats.size()) {
                preparedStatement.executeBatch();
                preparedStatement.clearBatch();
            }
        }
    } catch (SQLException sqlEx) {
        log.info(sqlEx.getSQLState());
    }
    return null ;
}
READ ALSO
How to create mysql container with initial data in kubernetes?

How to create mysql container with initial data in kubernetes?

I want to set initial data(script file which creates database and table) on MySQL of containerI have another pod which will talk with mysql pod and inserts data in the table

43
Tableview not showing new added data, only shows after restarting program (javafx)

Tableview not showing new added data, only shows after restarting program (javafx)

The tableview only shows new added data when I restart the programPlease help !

54
My SQL: I cannot count values from my table

My SQL: I cannot count values from my table

I am assigning my variable

40
It works local with xampp. The login works live, but the register does not

It works local with xampp. The login works live, but the register does not

Everything works fineThe error log does not show a thing

58