0

I am trying to add value into SQLite database only if it not exist in database with Java using if statement. I am totally confused.

try{

                String econ = String.valueOf(txt_economic.getText());
                String malami = "Select * from MPA1 where econcd = ?";
                pst = conn.prepareStatement(malami);
                rs = pst.executeQuery();
            while(rs.next()){

                String econcdi = rs.getString("econcd");


                if(econ.equals(econcdi) ){

           try{
                     //Insert goes here
}catch(Exception e){
}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please format your code properly, and correct at least compilation errors. Also you missed parameter for you prepared statement. – Sergei Sirik Aug 02 '17 at 23:50
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Aug 03 '17 at 00:00
  • 1
    here is an example https://stackoverflow.com/questions/19337029/insert-if-not-exists-statement-in-sqlite – Jon Goodwin Aug 03 '17 at 00:03
  • There's quite a few unmatched braces here... – halfer Aug 03 '17 at 00:11
  • and never ever swallow your exceptions `}catch(Exception e){ }` – Scary Wombat Aug 03 '17 at 01:53

0 Answers0