Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem updating fields on an access db

 
Patrick Dung
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it seems that i have problem when i use myResultSet.commit();
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic