public void cosUpdate(String sr,String name,String fname,String adress,String phone,String refernce,String tailor)
    {
                try{

                    String QUERY1 = "UPDATE Info1 SET FatherName = '"+fname+"' WHERE Sr = '"+sr+"'";
                    JOptionPane.showMessageDialog(null,QUERY1);
                                        Class.forName(JDBC_DRIVER);
                    connection=DriverManager.getConnection(DATABASE_URL);
                    statement=connection.createStatement();

                    result =statement.executeUpdate(QUERY1);
                    if(result >0)


                        JOptionPane.showMessageDialog(null,"Successfull");

                    else
                        JOptionPane.showMessageDialog(null,"UnSuccessfull");

                    }

                catch(Exception ex)
                {
                        JOptionPane.showMessageDialog(null,"Error in cosUpdate() Method","Error",JOptionPane.ERROR_MESSAGE);
                }
                finally{
                    try{
                        resultset.close();
                        statement.close();
                        connection.close();
                    }
                    catch(Exception ex){
                    }
                }

Recommended Answers

All 3 Replies

OK, thats some Java code. Is there a question or point you want to make?
ps Rather than the nested finally/try your code would be simpler with a Java 7 "try with resources".

Ugh, judging by this JOptionPane stuff, I assume this is part of a GUI? In which case I HOPE that this is part of a SwingWorker, and even then the JOptionPane stuff is probably not usuable in this form, as otherwise this is running on the same thread as the GUI which will introduce all sorts of problems.

See the API docs SwingWorker and google for some examples.

I also do not see where you are declaring your connection and statements. I see where you are defining them, but not where you are declaring them, so I can only assume they are instance variables, which will, most likely, also lead to a whole host of problems. Declare them locally.

But, other than those two obvious and grave errors, what is the actual problem you're having?

also, the next two parts of your code:

catch(Exception ex)
                {
                        JOptionPane.showMessageDialog(null,"Error in cosUpdate() Method","Error",JOptionPane.ERROR_MESSAGE);
                }




catch(Exception ex){
                    }

might cause you some trouble:

  1. always catch your exceptions as specific possible, don't just rely on the Exception class to do the Pokémon move and "Catch'em all!!"
  2. neither of the above catch block's 'll inform you of what is actually going wrong. the first one 'll just tell you in what method you have a problem. be a bit more specific. add some logging, or print the ex.getMessage() text instead of a Generic message
  3. the second catch is even worse, since it's hiding the exceptions. if something goes wrong there, how will you know?
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.