I am trying to write an Android app using Processing, and the app needs to communicate with an Access Database stored on the device. To do this, I am trying to use UCanAccess since Java 8 apparently dropped native support for this sort of thing. For whatever reason, since adding this code, running my app results in it crashing with the message "Unfortunately, My First Android App has stopped."
Why is this happening? Here is the portion of the code that relates to the question:
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import net.ucanaccess.converters.TypesMap.AccessType;
import net.ucanaccess.ext.FunctionType;
import net.ucanaccess.jdbc.UcanaccessConnection;
import net.ucanaccess.jdbc.UcanaccessDriver;
static class databasesHandler
{
static boolean readFromDatabase(int uid)
{
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess:///sdcard/Android/data/accessDatabase.mdb");
Statement stmt = con.createStatement();
stmt.execute("SELECT saveVal FROM userVals WHERE userId = " + str(uid));
ResultSet rs = stmt.getResultSet();
boolean spotFilled = false;
if (rs != null)
{
while (rs.next())
{
spotFilled = boolean(rs.getInt("saveVal"));
}
}
stmt.close();
con.close();
return spotFilled;
}
catch(Exception e) {
e.printStackTrace();
}
return false;
}
}
I have placed the UCanAccess library along with its lib folder within the code folder of my Processing sketch, and prior to me making this change, the app ran perfectly.