Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in updating a row in JDBC

 
bijoy bose
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am sorry for giving little confusing code...i hope this what are looking at...

 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't advanced, but it is JDBC-related, so I'm going to move this to the JDBC forum.
 
bijoy bose
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems that Ernest's moving to the JDBC forum didn't work. Trying again...
 
bijoy bose
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic