Problem in updating the data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeep84
    New Member
    • Sep 2007
    • 37

    #1

    Problem in updating the data

    Hi .. to all......
    i hav created the following codes in order to update the data... i don't know wats the problem.... plz help me to resolve my problem........ .

    Regards
    Pradeep

    Code:
     if(ae.getSource()==mod)
    {
         
    try 
    {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          con=DriverManager.getConnection("jdbc:odbc:prism");
          stmt1=con.createStatement();
          rs=stmt1.executeQuery("select * from Customerdetails");
          
          while(rs.next())
         {
            String query = "Update Customerdetails SET CompanyName="+s2+",Address="+s3+",PhoneNumber="+s4+",Contactperson="+s5+",EmailAddress="+s6+",FaxNumber="+s7+" where CustomerID='"+s1+"'";         
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con=DriverManager.getConnection("jdbc:odbc:prism");
            stmt2=con.createStatement();
            stmt2.executeUpdate(query);
      }    
    }
     catch(ClassNotFoundException e)
    {
      System.out.println(e);
    }    
    catch(SQLException e)
    {
      System.out.println(e);
    }
     }
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by pradeep84
    Hi .. to all......
    i hav created the following codes in order to update the data... i don't know wats the problem.... plz help me to resolve my problem........ .

    Regards
    Pradeep

    Code:
     if(ae.getSource()==mod)
    {
         
    try 
    {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          con=DriverManager.getConnection("jdbc:odbc:prism");
          stmt1=con.createStatement();
          rs=stmt1.executeQuery("select * from Customerdetails");
          
          while(rs.next())
         {
            String query = "Update Customerdetails SET CompanyName="+s2+",Address="+s3+",PhoneNumber="+s4+",Contactperson="+s5+",EmailAddress="+s6+",FaxNumber="+s7+" where CustomerID='"+s1+"'";         
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con=DriverManager.getConnection("jdbc:odbc:prism");
            stmt2=con.createStatement();
            stmt2.executeUpdate(query);
      }    
    }
     catch(ClassNotFoundException e)
    {
      System.out.println(e);
    }    
    catch(SQLException e)
    {
      System.out.println(e);
    }
     }
    Did you commit after Updation?

    [code=java]
    Connection con = null;
    .
    .
    .
    con.commit();
    [/code]

    Have a look at this.

    Debasis Jana

    Comment

    • pradeep84
      New Member
      • Sep 2007
      • 37

      #3
      Now i added
      Code:
      con.commit();
      but still i didn't get the output...

      regards
      pradeep

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by pradeep84
        Now i added
        Code:
        con.commit();
        but still i didn't get the output...

        regards
        pradeep
        Where you added that line?
        After "stmt2.executeU pdate(query)" :-)
        And here you used two connections.
        Try to have this style of coding.

        [code=java]
        try{
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        Class.forName(" your driver class");
        con = DriverManager.g etConnection(.. .);
        stmt = con.createState ment();
        rs=stmt.execute Query("sql query");
        }
        catch(SQLExcept ion e)
        {
        }
        finally{
        con.close();
        rs.close();
        stmt.close();
        }
        [/code]

        Debasis Jana

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Do not load the driver twice. Why are creating two connections?
          Change those things try it and if you get a problem post the exact problem that you get. Don't just say "it does not work".

          Comment

          Working...