mardi 14 avril 2015

How to check if a row exist in the SQLite table with a condition

I am using SQLite local database in my software. I want to check if a row exists based on the giver values of the row. for example : "SELECT * FROM ftp WHERE Host LIKE '"+ host +"' AND Username LIKE '"+ username +"' "


But I want to get boolean result so if finds the record do something and if not do something else. Hoe can I do this?


here is what I tired but it is always true, since it check if quesry runs and not if it returns data.



public void ftpTableCheck(String host, String port, String username, String password){
try{
String query = "SELECT * FROM ftp WHERE Host LIKE '"+ host +"' AND Username LIKE '"+ username +"' ";
PreparedStatement pst = conn.prepareStatement(query);

if (pst.execute() == true){
System.out.println("true");
}

}catch(Exception e){
e.printStackTrace();
}
}


Any idea how to fix it? Thanks


Aucun commentaire:

Enregistrer un commentaire