• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

update statement seems not working

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,im trying to connect to a access a MS Access database from which the knowledge i gained from Sun Java's tutorials.
Although the select code works it seems that the following update statement doesn't work.
The statement updates the data in the recordset but not in the database itself.
 
Mohamed Manas
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the code:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String database="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
String filename="COFFEEBREAK.mdb";
String url=database+filename;

Connection conn=DriverManager.getConnection(url);

Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("SELECT COF_NAME FROM COFFEES WHERE PRICE=7.99");

rs.next();
rs.updateString("COF_NAME","Foldgers");
rs.updateRow();
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would avoid using updateString/updateRow at all, not all databases support it. Instead, I'd recommend you write an update statement and execute it as a separate query.
 
Mohamed Manas
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your review.
Anyway I found out that I hadn't included the close() method for the connection after updating the resultset.
Since I am a newbie I will make sure I will not make this kind of silly mistakes anymore.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic