Can't make the result set updatable with ucanaccess

I have tried most of the examples found here and on the web, but I cannot open the MS access database (2002 or 2013) and get the updatable result set using UCanAccess. This same code uses the JDBC driver: ODBC / connect / works. I wrote a short test code to check the concur_updatable to test this, so I am missing something. I am using JDK 1.7 on a Win7 machine. I also have another machine with the same results. It works:

/*
class jdbc, for testing jdbc:odbc CONCUR_UPDATABLE.
*/

import java.sql.*;

public class jdbc {

private static String dbFQN;

public static void main(String[] args) {

try {
dbFQN = ("C:\\phil\\programming\\kpjl2002.mdb");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + dbFQN;
System.out.println("Loading database: " + database);
Connection conn = DriverManager.getConnection(database, "", "");
Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
// Fetch records from table
String selTable = "SELECT * FROM " + "tblLibrary" + " ORDER BY Artist, Cat, Cart";
s.execute(selTable);
ResultSet rs = s.getResultSet();

int concurrency = rs.getConcurrency();
if(concurrency == ResultSet.CONCUR_UPDATABLE)
{
System.out.println("rs is updatable");
} else {
System.out.println("rs Not updatable");
}

s.close();
conn.close();
} //close try
catch (Exception ex) {
ex.printStackTrace();
}   //close catch
}   //close main method

}   //close dbAccess class

      

The conclusion is that rs is being updated.

This does not work:

/*
class ucan, for testing ucanaccess CONCUR_UPDATABLE.
C:\jdk1.7.0_79\jre\lib\ext\ucanaccess-2.0.9.5.jar
C:\jdk1.7.0_79\jre\lib\ext\hsqldb.jar
C:\jdk1.7.0_79\jre\lib\ext\jackcess-2.1.0.jar
C:\jdk1.7.0_79\jre\lib\ext\commons-lang-2.6.jar
C:\jdk1.7.0_79\jre\lib\ext\commons-logging-1.1.1.jar

also present:
C:\jdk1.7.0_79\jre\lib\ext\commons-logging-1.2.jar
C:\jdk1.7.0_79\jre\lib\ext\commons-lang3-3.4.jar
*/

import java.sql.*;

public class ucan {

private static String dbFQN;

public static void main(String[] args) {

try {
dbFQN = ("C:\\phil\\programming\\kpjl2002.mdb");
String database = "jdbc:ucanaccess://" + dbFQN;
System.out.println("Loading database: " + database);
Connection conn = DriverManager.getConnection(database, "", "");
Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
// Fetch records from table
String selTable = "SELECT * FROM " + "tblLibrary" + " ORDER BY Artist, Cat, Cart";
s.execute(selTable);
ResultSet rs = s.getResultSet();

int concurrency = rs.getConcurrency();
if(concurrency == ResultSet.CONCUR_UPDATABLE)
{
System.out.println("rs is updatable");
} else {
System.out.println("rs Not updatable");
}

s.close();
conn.close();
} //close try
catch (Exception ex) {
ex.printStackTrace();
}   //close catch
}   //close main method

}   //close dbAccess class

      

the conclusion is that rs is not updated. Therefore, I cannot update or insert rows into the result set.

The above code is an operational part of a larger project where UCanAccess can read a table and put content in jList and jTextarea with formatting. When I started writing code to update or add a new entry, I ran into this problem.

Apologies if this is a little longer. Anyone have an idea what I am missing or something amiss?

BTW this is one of my 2 sites for good, helpful Java answers.

UPDATE: Got the idea from an old co-worker, the original database may have been copied from the original Access97 db. up to 2000 dB. I used 2013 Repair and Compact to create the "new" beta versions of 2002 and 2013. Access should retain type "97" even when doing what I did. So I created a new dummy db 2013 for testing and UCanAccess will report the result set as updatable. I'll try to recreate the current db record data in a new database file and see if that works. I hope this is a problem as UCanAccess does not support updating with Access97 db. I'll let you know what I find. Thank.

+3


source to share


2 answers


I used 2013 Repair and Compact to create the "new" beta versions of 2002 and 2013. Access should retain type "97" even when doing what I did. So I created a new dummy db 2013 for testing and UCanAccess will report the results as updatable.

The Compact and Repair Database feature in Access does not change the version of the database file. If you have (which you suspect) a database file of an older version, you must use the "Save Database As" function under File> Save and Publish * to convert the database file to a newer version.



* (... at least where it is in Access 2010.)

+1


source


Okay, after a nice weekend eating brothers and drinking good beer at Germanfest, I finally got to work. I decided to abandon MS Access db and put 472 records in SQLite db. With this, I was able to get PreparedStatements to work in order to display records in jList and JTextArea, add a new record, and update a couple of fields in an existing record within the same test application run. It is both a GUI command line interface and NetBeans 8.0 so I think my problems are solved. After completing several summer projects, I will be back to re-writing the original VB application using Java. Thank you, Gord, and everyone is here.



0


source







All Articles