I scoured the web and found nothing for this. I have a group of records in a JTable and I need to export these records to an existing table in an MS Access database. I need to be able to append records to this table as there may already be data present.
I've spent the last two days reading up and learning about Jackcess and UcanAccess libraries. I'm absolutely tapped out at this point so if someone would be kind enough to post some code I would really appreciate it.
Edit: 5:15 PM PT Monolithic task for sure. Thanks to all for the helpful advice. I just now managed to arrive at a solution. I read a post that helped me understand the contents of a jTable are really only there for display purposes and not the ideal source to be using to export data sets to other databases. So I used the ImportUtil in the Jackcess library to directly export the ResultSet to my Access database. The answer was right in front of me the whole time: http://jackcess.sourceforge.net/ (it's the fourth code sample from the top)
So here is the AccessExporter.java class I created for this. It takes three parameters a ResultSet object, "TableName" and a File object defining where the database file is located. Here's the code:
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.util.ImportUtil;
import java.io.File;
import java.sql.ResultSet;
/**
*
* @author petehahn
*/
public class AccessExporter {
void fillData(ResultSet jTableResults, String dbTableName, File dbFile){
try {
Database dbTarget = DatabaseBuilder.open(dbFile);
new ImportUtil.Builder(dbTarget, dbTableName).importResultSet(jTableResults);
dbTarget.close();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}