Im having a problem with updating data in SQLite
this is the full code who execute after pressing the button

        try {

        PrintWriter writer = new PrintWriter("d:\\"+LBL1.getText()+"\\"+TL3.getText()+"_"+TL2.getText()+"_"+TL4.getText()+"_"+TL5.getText()+"_"+TL1.getText()+".txt", "UTF-8");
            writer.println("Invoice Number = "+TL1.getText());
            writer.println("Seda = " +TL3.getText());
            writer.println("Date = " +TL2.getText());
            writer.println("Documental Class = " + TL4.getText());
            writer.println("Status = " + TL5.getText());
            writer.println("Subject Name = "+tf1.getText());            
            writer.println("Service = " + tf2.getText());
            writer.println("Price = " +TA3.getText());
            writer.println("VAT Number = "+TA2.getText());
            writer.println("Total price = " +TA1.getText());


            writer.close();

     String te1 = tf1.getText();
        String te2 = TA3.getText();
        String te3 = TA2.getText();
        String te4 = TA1.getText();
        String te5 = tf2.getText();
        String te6 = TL1.getText();
         String sql = "UPDATE DataImput SET SubjectName='"+te1+"' ,VATnumber='"+te3+"' ,Service='"+te5+"' ,Price='"+te2+"' ,Totalamount='"+te4+"' WHERE Invoicenumber='"+te6+"'";

           pst=conn.prepareStatement(sql);

           rs= pst.executeQuery();


        }catch(Exception e){        
            JOptionPane.showMessageDialog(null, e);            
        }finally{
    try{
       rs.close();
       pst.close();                
    }
        catch(Exception e){        
        }                
    }

it work to create the file. but it does not execute querry to update the data. where is the mistake?

catch(Exception e){        
        }  

code like that is always bad.

have you debugged the code? are you trying to update an existing line?

String sql = "UPDATE DataImput SET SubjectName='"+te1+"' ,VATnumber='"+te3+"' ,Service='"+te5+"' ,Price='"+te2+"' ,Totalamount='"+te4+"' WHERE Invoicenumber='"+te6+"'";

if there is no row with invoicenumber equal to the value of te6, that would explain it.

Just print the entire String and check if all values are as you expect them to be

"code like that is always bad."
Actually that is the one place where an empty catch is often OK - inside a finally block where yoy are just trying to tidy up anything left untidy.

I dont have problem with the connection string, because it should show that as problem, it does not execute the query. that is the problem I'm facing

James: if a connection fails to close because it was already closed, I would like to know.

Altjen: how do you know it doesn't execute?

"if a connection fails to close because it was already closed, I would like to know."

Fair enough (although for most streams etc a second close will just be ignored). But the finally will be executed even after the try block has failed, so close etc may fail in the finally because they were never opened. So then you start to have tests in the finally to see what needs to be cleaned up, and catches if that doesn't work, and the whole thing balloons out of proportion.
Often all you want is to be sure that anything open will be closed when the method finishes, in which case I would go with the empty catch.

The real answer, of course, is to use try-with-resources

Edited 1 Year Ago by JamesCherrill

Stultuske: Catch (Exception e) show error that querry does not execute.

but a friend told me this

 String sql = "UPDATE DataImput SET SubjectName='"+te1+"' ,VATnumber='"+te3+"' ,Service='"+te5+"' ,Price='"+te2+"' ,Totalamount='"+te4+"' WHERE Invoicenumber='"+te6+"'";

           pst=conn.prepareStatement(sql);

           pst.executeUpdate();

it work now.

Catch (Exception e) show error that querry does not execute.

see, for future reference: it might be a good thing to include this information (and the actual stacktrace) in the original posts

This question has already been answered. Start a new discussion instead.