public void fetch() throws Exception{ Connection con = null; con = sqliteConnection.sqliteConnector(); PreparedStatement pst = null; ResultSet rs = null; try { String quest=userInputField.getText().toLowerCase().trim().toString(); String sql = "select * from user where name LIKE '% %'"; pst = con.prepareStatement(sql); //pst.setString(1, quest);//getting array index out of bounds 0 rs = pst.executeQuery(); if(rs.next()){ String ans = rs.getString("answer"); textarea.append(ans +"\n"); }else { textarea.append("Nothing was found." +"\n"); } System.out.println("Succesfully retrieved data from bcsdb"); if (pst != null) pst.close(); System.out.println("PST was successfully closed!"); if (rs != null) rs.close(); System.out.println("PS was successfully closed!"); if (con != null) con.close(); System.out.println("Con was successfully closed!"); } catch(Exception ex) { ex.printStackTrace(); } }
"select * from user where name = ?"
"select * from user where name = \"" + quest + "\";"
String sql = "select * from user where name = ' " +quest+ " '; ";//nothing is found
//String sql = "select * from user where name match ' ' ";//prints first row only//String sql = "SELECT * FROM user WHERE name like ? ";//shows first row only//String sql = "SELECT * FROM user WHERE LOWER(name) LIKE ?";//String sql = "select * from user where name LIKE :name"; //show answer from first row onlyString sql = "select * from user";//first row is returned//String sql = "select * from user where name LIKE '"+quest+"' ";//showing first row only//String sql = "select * from user where name = '%" + quest + "%' ";//nothing is retrieved from the db//String sql = "select * from user where name=?";//not fetching any data//String sql = "select * from user where name like 'a%'";//String sql = "SELECT name, surname FROM user WHERE UPPER(name) LIKE UPPER('"+quest+"') || '%'";//String sql = "select * from user where name like '%" + quest + "%'";//show from first row only<code>
"select * from user";
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)