I'm developing an application with eclipse
and using an object related mapping (ORMLite) to access my mysql
server. The datalayer is another project compiled in java
and bound as a reference to my android application.
I've referenced in the datalayer project every *.jar file used with ormlite. But when running my application I get this error message:
"Could not find class 'com.j256.ormlite.jdbc.JdbcConnectionSource',
referenced from method
com.pos.datalayer.querybuilder.DatabaseWorker.connectionSetup"
Here is my code of the DatabaseWorker-class:
public class DatabaseWorker implements DatalayerWorkable {
private Type tableMapping = null;
private String actionOnDatabase = null;
private UserBO persistedUser = null;
private Type retVal = null;
public static String hostString = "jdbc:mysql://lucid.selfhost.me/pos";
private static JdbcConnectionSource connection = null;
public DatabaseWorker () { };
public Type loadData( String databaseAction, final Type tableMap ) {
actionOnDatabase = databaseAction;
tableMapping = tableMap;
Thread workerThread = new Thread(new Runnable(){
public void run() {
try {
connection = connectionSetup();
if(actionOnDatabase == "GetLogin"){
retVal = loadUserData(tableMap);
}else if (actionOnDatabase == "loadHotDealz"){
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(connection != null){
//closeConnection(connection);
connection = null;
}
}
}
});
workerThread.start();
return retVal;
}
public boolean persistData( String databaseAction, Type tableMap ) {
Thread workerThread = new Thread(new Runnable(){
public void run(){
}
});
return false;
}
private JdbcConnectionSource connectionSetup() throws SQLException{
//set up sql-connection
JdbcConnectionSource connection = new JdbcConnectionSource(hostString);
((JdbcConnectionSource) connection).setUsername("guest");
((JdbcConnectionSource) connection).setPassword("ObivanK3nobi");
return connection;
}
private void closeConnection(JdbcConnectionSource openedConnection){
try{
if(openedConnection != null){
openedConnection.close();
}
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private Type loadUserData(Type tableMapping) throws SQLException{
Dao<UserBO, String> accountDao = null;
if(connection != null){
accountDao = DaoManager.createDao(connection, tableMapping.getClass());
String currentUser = ((UserBO) tableMapping).getUser();
//execute query
persistedUser = accountDao.queryForId(currentUser);
if(persistedUser != null){
persistedUser.setIsLoggedin(1);
accountDao.update(persistedUser);
}
}
return persistedUser;
}
public Type getDatabaseResult(){
return retVal;
}
public void databaseObjCallback(Type databaseResult) {
throw new UnsupportedOperationException("Not implemented yet");
}
}
I would appreciate any help to solve my problem!