I have a semester long project that I have been working on in Android with a four person group. It is due tomorrow. I was planning on using JDBC for Android, but I have run into an ugly problem I had seen before. No matter what I do, my Android will not recognize external references. For awhile I avoided the problem by copying source code into my project.
However, with JDBC, I need a JAR Driver to in order to connect to the MySQL Database. So you are aware, I am adding the JAR by:
- Creating a folder
- Importing the JAR into that folder
- Adding the JAR to the BuildPath in the Android Project.
I also tried adding an external Java Project by adding it to the BuildPath. There were no Compile errors, but I got ClassNotFound errors when the code executed on my (Ice Cream Sandwich) phone. The project is in Android 2.2. I have heard making an Android Library project will solve this, but I am not interested in that solution as it defeats the purpose of the project reference in my case.
With the JDBC Driver, the following RuntimeException was thrown in my project here:
private final static String driver = "com.mysql.jdbc.Driver";
private final static String userName = "sqluser";
private final static String passwd = "sqlpw";
public Query() {
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// System.err
// .println("error in DB connection: can not find the DB driver");
throw new RuntimeException("Driver not found");
}
The code works fine as a Java Application.
Any solution that works would be highly appreciated. Since the project is due tomorrow, it doesn't have to be the most elegant approach. Also (not that it matters), my project is connected to a SVN repository via SubClipse. Thanks in advance!