UPDATE doesn't work
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   danko_greiner
Posted On:   Wednesday, December 19, 2001 07:49 PM

This is code: stmt="UPDATE users SET age=age+1 WHERE username LIKE 'Mike'"; { if(conn == null) // if Connection has not been set RS = null; else { try { Statement s = conn.createStatement(); int i = s.executeUpdate(stmt); System.out.println(i); } catch (java.lang.Exception ex) { ex.printStackTrace(); } } return(RS); } System.outprintlne(i) correctly shows how many recors should be updated but when i look into my database (MS Access 2000) the records are unchanged !? when i copy/paste sql statement from abouve directly into Access Query it work OK ?!?! any ideas?    More>>

This is code:

			
stmt="UPDATE users SET age=age+1 WHERE username LIKE 'Mike'";
{
if(conn == null) // if Connection has not been set
RS = null;
else
{ try {
Statement s = conn.createStatement();
int i = s.executeUpdate(stmt);
System.out.println(i);
}
catch (java.lang.Exception ex) {
ex.printStackTrace();
}
}
return(RS);
}


			
System.outprintlne(i) correctly shows how many recors should be updated but when i look into my database (MS Access 2000) the records are unchanged !?

when i copy/paste sql statement from abouve directly into Access Query it work OK ?!?!
any ideas?
THANX!
   <<Less

Re: UPDATE doesn't work

Posted By:   Jason_Jakob  
Posted On:   Sunday, January 6, 2002 11:10 PM


//try this instead and see what happens

Statement stmt = conn.createStatement();

int result = stmt.executeUpdate("UPDATE users SET age=age+1 WHERE username LIKE 'Mike');

//your jdbc driver may have some problems with preparedStatement

Re: UPDATE doesn't work

Posted By:   danko_greiner  
Posted On:   Friday, December 21, 2001 04:39 PM

PROBLEM SOLVED, Thanx all

Re: UPDATE doesn't work

Posted By:   Anonymous  
Posted On:   Friday, December 21, 2001 09:35 AM

You might try


WHERE username LIKE 'Mike%'

Re: UPDATE doesn't work

Posted By:   zhaohua_meng  
Posted On:   Thursday, December 20, 2001 08:51 AM

1. Try conn.setAutoCommit(true) before you get Statement or execute conn.commit() after your s.executeUpdate(stmt).


2. Put a () around your 'Mike'


Just try to see if it works. It seems nothing wrong with your code.

About | Sitemap | Contact