If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Problem with updateString method of ResultSet in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-07, 14:29
g_sri1987 g_sri1987 is offline
Registered User
 
Join Date: Oct 2007
Posts: 5
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****ntime.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
Reply With Quote
  #2 (permalink)  
Old 10-17-07, 16:41
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
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.
Reply With Quote
  #3 (permalink)  
Old 10-18-07, 13:48
g_sri1987 g_sri1987 is offline
Registered User
 
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 13:59.
Reply With Quote
  #4 (permalink)  
Old 10-18-07, 14:25
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
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();
Reply With Quote
  #5 (permalink)  
Old 10-20-07, 00:59
g_sri1987 g_sri1987 is offline
Registered User
 
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();
}
Reply With Quote
  #6 (permalink)  
Old 10-20-07, 20:46
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On