• 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

problem updating fields on an access db

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it seems that i have problem when i use myResultSet.commit();
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic