1

I have a problem transferring listview items from a listview to a SQL database on netbeans using javaFX.

Here is a method that is called when you click the button to add to the listView items to the database (Add Order). I need all the items in the listview to be written to a column.

 private static void insertColl(){
    try{
        stmt = conn1.createStatement();
        String description = listView.getText();
        String query = " insert into ORDERS(DESCRIPTION)"
        + " values (?)";

    PreparedStatement preparedStmt = conn1.prepareStatement(query);

    preparedStmt.execute();
        stmt.close();
    }
    catch (SQLException sqlExcept){
        sqlExcept.printStackTrace();
    }

Here is what our javafx project looks like, the listview in question has an arrow pointing next to it.
Apologies if I am not using the correct terminology, as I am new to this. Thank you for your help. enter image description here

1
  • can you please post your error? Commented Mar 21, 2017 at 14:52

2 Answers 2

1

I think you misunderstood how PreparedStatement work, you should to set your paremetres to your statement ;

PreparedStatement preparedStmt = conn1.prepareStatement(query);
preparedStmt.setString(1, description );//<-------------------
Sign up to request clarification or add additional context in comments.

Comments

0

You missed to add to the PreparedStatement the values, and try with executeUpdate().

Also, you are not using the first Statement.

PreparedStatement preparedStmt=conexion.getConexion().prepareStatement(query);

preparedStmt.setString(1, description);

preparedStmt.executeUpdate();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.