wood burning stoves 2.0*
The moose likes JDBC and the fly likes problem in updating a row in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in updating a row in JDBC" Watch "problem in updating a row in JDBC" New topic
Author

problem in updating a row in JDBC

bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
try
{
con = DriverManager.getConnection(url, "", "");
stmtA = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);

queryx ="Select * From cleanTableA order by START_DATE";
ResultSet rsAcd = stmtA.executeQuery(queryx);
while(rsAcd.next())
{
if(!dod.equals(""))
{
........
}
if (StartDate.after(TmpStudyEnd))
{
rsAcd.deleteRow();
rsAcd.previous(); .......
}
else
{
Date EndD = rsAcd.getDate(3);
if(EndD.after(TmpStudyEnd))
{
EndD = TmpStudyEnd;
df2 = DateFormat.getDateInstance(DateFormat.SHORT);
String tmpend = df2.format(EndD);
------> rsAcd.updateLong(3, java.sql.Date.parse(tmpend));
}

}
this -> line is not working....it is trying to update the date in the 3rd column of the Table (DB i mean)

i will really appreciate if some one can pull me up from this great trouble i am in.....Thanks for any help i get


Bijoy
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
What do you mean by it's not working?

Your code will be easier to read if you use "Code" tags (buttons below the add reply button).
bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
i am sorry for giving little confusing code...i hope this what are looking at...

K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Originally posted by bijoy bose:
it is trying to update the date in the 3rd column of the Table (DB i mean)


This is what it is meant to do. Quote from the API: Updates the designated column with a long value. Seems fine to me.

What were you expecting?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

This isn't advanced, but it is JDBC-related, so I'm going to move this to the JDBC forum.


[Jess in Action][AskingGoodQuestions]
bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
but it is not updating ...and i cant figure out why...is there is any problem with connection (con) or statement (stmtA)?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
I usually avoid "select *" since the order of the columns returned can change. For example, if you create a table with three rows (A, B, D) in the database but later insert a new third column (A, B, C, D), using "select *" in most databases will return them as (A, B, D, C). Does this work against some databases (created new after adding a column) and not others (created earlier and altered in-place)?

In any case, java.util.Date.parse(String) was deprecated in JDK 1.1. Use SimpleDateFormat with the parse format that you expect.

Finally, please explain what "it is not updating" means specifically: compile error (unlikely but possible), exception, wrong value in database, or "nothing happens"?
bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
i am getting an SQL exception if i delete any row by using DeleteRow() method of ResultSet class. exception is: "Invalid Cursor State". But the code is actulally doing the work i.e is deleting the row from DB
bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
i am sorry i am supposed to say somthing on ypdating problem....just ignore the other question!!


the problem is i am trying to update a date column in a specific row...so when i am trying to set a date in a specific column in a specific row, i am using UpdateLong(columnindex, date). method of resultset class it is not updating. i mean nothing is changed in the actuall DB
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Maybe I'm missing something...

If you are using ResultSet.getDate() why aren't you using ResultSet.updateDate()?

1. EndD = rsAcd.getDate(3);
2. rsAcd.updateLong(3, java.sql.Date.parse(tmpend));
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Seems that Ernest's moving to the JDBC forum didn't work. Trying again...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
bijoy bose
Ranch Hand

Joined: Mar 27, 2004
Posts: 32
Thanks Carol...though i have tried UpdateDate() method earlier but i was sending instance of util.date thats y i was getting an error but now i got it!

rsAcd.UpdateDate(int columnIndex, SQl.Date);
rsAcd.UpdateRow();

this code worked for me finally.

Thanks folks...

 
jQuery in Action, 2nd edition
 
subject: problem in updating a row in JDBC
 
Similar Threads
problem of updating
servlets
main() methods
How to retrieve multiple row data from oracle table and show it in jsp page
Parsing Date/Time String - Urgent