File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes update statement seems not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "update statement seems not working" Watch "update statement seems not working" New topic
Author

update statement seems not working

Mohamed Manas
Greenhorn

Joined: Jun 02, 2008
Posts: 24
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.


It is better to make mistakes now and on purpose than later and accidentally...
Mohamed Manas
Greenhorn

Joined: Jun 02, 2008
Posts: 24
the code:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String database="jdbcdbcriver={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();
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703
    
    5

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.


My Blog: Down Home Country Coding with Scott Selikoff
Mohamed Manas
Greenhorn

Joined: Jun 02, 2008
Posts: 24
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: update statement seems not working
 
Similar Threads
Accessing One table with multiple Threads and Inserting Values
If Statement&Equals
Difference between execute() and excuteQuery()
pleeez help
Updatable resultsets