Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2007
    Posts
    5

    Unanswered: Problem with updateString method of ResultSet in DB2

    hello sir,
    I have never worked with DB2 before.I am facing a problem with updation of row in DB2.The following piece of code is not working in DB2...but works fine for MSAccess and Oracle.

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con1=DriverManager.getConnection ("jdbcdbc:tgmc","db2admin","laptop");
    Statement stmt1 = con1.createStatement(ResultSet.TYPE_SCROLL_SENSITI VE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stmt1.executeQuery("select * from \"GAURAV SRIVASTAVA\".form");
    while(rs.next())
    {
    int f_id=rs.getInt("form_id");
    if(f_id==11)
    {
    rs.updateString("status","ri");//here is the problem
    rs.updateRow();
    }
    }
    con1.close();

    The above code throws NullPointerExecption as follows::

    java.lang.NullPointerException
    sun.jdbc.odbc.JdbcOdbcBoundCol.setRowValues(Unknow n Source)
    sun.jdbc.odbc.JdbcOdbcResultSet.updateBytes(Unknow n Source)
    sun.jdbc.odbc.JdbcOdbcResultSet.updateString(Unkno wn Source)
    sun.jdbc.odbc.JdbcOdbcResultSet.updateString(Unkno wn Source)
    org.apache.jsp.app_005fnf_jsp._jspService(app_005f nf_jsp.java:67)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:332)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:802)


    Can you help me with this error??? Or can you suggest me an appropiate method for performing the task

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Few things to look at:
    - make sure the column named "status" exists;
    - make sure it's actually "status", not "STATUS";
    - use DB2 JDBC driver.

    BTW, writing "select * from.." is a bad habit; you should specify column names explicitly.
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Oct 2007
    Posts
    5
    i tried them all....its still not working.

    i am using IBM DB2 ODBC DRIVER - DB2COPY1.
    thats the driver provided in Window's XP.Is it the driver thats creating the problem??? Can u provide me some links from where I can get the DB2 JDBC driver???

    can u suggest me some other methods for updation of a row???
    Last edited by g_sri1987; 10-18-07 at 14:59.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by g_sri1987
    Can u provide me some links from where I can get the DB2 JDBC driver???
    http://www-1.ibm.com/support/docview...id=swg27007053

    From there you can find DB2 client software matching your server version and fixpak level.

    Quote Originally Posted by g_sri1987
    can u suggest me some other methods for updation of a row???
    Code:
    PreparedStatement s = con1.prepareStatement("UPDATE table SET column = ? WHERE anothercolumn = ?");
    s.setString(1, "ri");
    ...
    ...
    s.executeUpdate();
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    Oct 2007
    Posts
    5
    thanx buddy.....
    i did it in a slightly different manner.
    Connection con1=DriverManager.getConnection("jdbcdbc:tgmc");
    Statement stmt1 = con1.createStatement(ResultSet.TYPE_SCROLL_SENSITI VE,ResultSet.CONCUR_UPDATABLE);
    try
    {
    stmt1.executeQuery("update \"GAURAV SRIVASTAVA\".form set ststus='ri' where form_id = "+ t);
    }
    catch(Exception e)
    {
    con1.close();
    }

  6. #6
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    That's great, buddy, but you have two problems here:
    - creating the statement text "on the fly", as you do, has performance and security implications and should be avoided when possible. PreparedStatement is the preferable approach;
    - UPDATE is not a query, so your method will not work with later versions of DB2 drivers. Use executeUpdate() or execute() methods instead.
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •