wood burning stoves 2.0*
The moose likes JDBC and the fly likes problem updating fields on an access db Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem updating fields on an access db" Watch "problem updating fields on an access db" New topic
Author

problem updating fields on an access db

Patrick Dung
Greenhorn

Joined: Dec 09, 2001
Posts: 4
I cannot update an Access DB using JDBC. This is my small test program:
import java.sql.*;
import java.io.*;
public class testdb {
public static void main (String args[]) throws Exception{
String user = "admin";
String password = "";
String url = "jdbc dbc:MyAccessDSN";
Connection myConnection;
Statement myStatement;
ResultSet myResultSet;

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
myConnection = DriverManager.getConnection (url, user, password);

myStatement = myConnection.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
myResultSet = myStatement.executeQuery("Select * from school");

myResultSet.absolute(2);
myResultSet.updateString ("name", "new name");
myResultSet.updateString ("isTeacher", false);
myResultSet.updateRow();
} catch (SQLException e) {
System.err.println("An error occurred: " + e);
} catch (ClassNotFoundException e) {
System.err.println("An error occurred: " + e);
}

} //main
} //testdb
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Are you getting an error or the update is just not working.? Again what version of the JDBC are you using? MS Access may not support some of the constructs you have in your code.
------------------
Bosun
SCJP for the Java� 2 Platform


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

If the problem is simply that it is not updating, try closing the db resources or performing a select on the same connection after you perform the update.
I've never had the problem myslef, but ACCESS seems to have a problem commiting updates without an extra "push"
Dave
Patrick Dung
Greenhorn

Joined: Dec 09, 2001
Posts: 4
it seems that i have problem when i use myResultSet.commit();
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

I believe that access does not support transactions(or it could be that some underlying ODBC drivers don't support it). So you can't use commit/rollback, but only the default autocommit.
does your program throw a SQLException? if so, what was the error message? if not, what, specifically, is the "problem" that you mentioned?
Jamie
Patrick Dung
Greenhorn

Joined: Dec 09, 2001
Posts: 4
Sorry, the source code I post don't has problem. I've forget to put the resultset.commit() to the source code I post. So, I ask when to use resultset.commit() in the following post. And you answered my question.
 
jQuery in Action, 2nd edition
 
subject: problem updating fields on an access db
 
Similar Threads
can't update database?
Newbie problem. JDBC Error
Custom jdbc function won't work in other classes
DriverManager error
JDBC Oracle connection error