lundi 9 mars 2015

Generic method to get data from any table using ORMlite

I Am trying to create method that can get all the data from any table from SQLite using ormlite and Dao class, I do not know which values set in Dao , the code looks like:



public <T> List<T> getAllRecords(Class<T> klass){
String databaseUrl = "jdbc:sqlite:c:\\Users\\workspace\\my_sqlite";
SQLiteDBLayer sQLiteDBLayer = new SQLiteDBLayer(SQLiteDBLayer.ConnectionType.READER);
ConnectionSource connectionSource = null;
try {
connectionSource = new JdbcConnectionSource(databaseUrl);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Dao<???, String> transfor = null ; //???? is where I'm stuck
List<T> results;
try {
transfor =DaoManager.createDao(connectionSource,????);//And Here also
results= (List<T>) transfor.queryForAll();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Aucun commentaire:

Enregistrer un commentaire