0
public void Search(ActionEvent event)
{
    try
    {
        Connection conn = SqliteConnection.Connector();
        PreparedStatement ps = conn.prepareStatement("SELECT FROM Studentlist WHERE ID LIKE ?% ");
        ps.setString(1, this.search.getText());

        ResultSet rs = conn.createStatement().executeQuery(String.valueOf(ps));
        while (rs.next())
        {
            this.data.add(new StudentData(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7)));
        }
    }
    catch (SQLException e)
    {
        System.out.println(e);
    }
}

I am trying to search data by id from the database through tableview javafx gui

i want it to return all the data starting with the letters i input in the textfield

i connected the database through the class and method i created SqliteConnection.Connector(); prepared a string got the value from the search textfield... this.data is the name of observablelist.. my issue is i dont get any result in the tableview when i type a valid ID

dedicated
  • 19
  • 6
  • The query used the db will be something like `SELECT FROM Studentlist WHERE ID LIKE "input"%` which is incorrect SQL syntax – fabian Nov 07 '18 at 17:47
  • This is marked as duplicate but it talks about observable list in a tableview and i agree it talks about the use of like in database – Zuher Abud Nov 08 '18 at 00:01

1 Answers1

0

Instead of

ResultSet rs = conn.createStatement().executeQuery(String.valueOf(ps));

You want to do

ResultSet rs =  ps.executeQuery();
Justin
  • 1,356
  • 2
  • 9
  • 16
  • i changed`'PreparedStatement ps = conn.prepareStatement("SELECT FROM Studentlist WHERE ID LIKE '?'%"); ps.setString(1, this.search.getText()); ResultSet rs = ps.executeQuery();`but still not showing search results – dedicated Nov 08 '18 at 00:38
  • put the % in your setString method like this: ps.setString(1, this.search.getText()+"%"); and of course remove the % from your prepareStatement function argument. – Justin Nov 08 '18 at 00:52