简体   繁体   中英

PreparedStatement won't send data over to database

I'm unsure as to why my program won't actually send the data supplied over to the table in my database table. I'm using a JavaFX application table to select a client from the table when selected and when signed in, the method sends the info to the DBconnect class to perform the operation.

Method to send the data to the DBconnect class:

public void signIn() throws SQLException {
    BloomClient person = clientList.getSelectionModel().getSelectedItem();
    dBconnect.sendToRoster(person.getFirstName(),person.getLastName());
}

Method to perform PreparedStatement :

public void sendToRoster(String fName, String lName) throws SQLException {
    PreparedStatement st = c.prepareStatement("INSERT INTO sign_in_roster VALUES(?,?,?,?);");
    c.setAutoCommit(false);
    try {
        st.setString(1,fName);
        st.setString(2,lName);
        st.setString(3, systemDate());
        st.setString(4, systemTime());
        c.commit();
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }
}

You've set all the bind variables, but you've forgot to execute the statement:

st.setString(1,fName);
st.setString(2,lName);
st.setString(3, systemDate());
st.setString(4, systemTime());
st.executeUpdate(); // Here
c.commit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM