Recording a query using ORMLite

How to write a query using ormlite instead of using .create or any other similar thing? Could you show me how this simple example is:

SELECT name FROM client 

EDIT, as I can’t answer myself: I think I had to look a little more, anyway, I found how to do this with QueryBuilder as follows:

 newDao.query(newDao.queryBuilder().where.eq("name",valueofname) 

If someone knows how to write a complete query that would be great, otherwise I will stick to this solution

+8
query-builder ormlite
source share
1 answer

How to write a query using ormlite instead of using .create or any other similar thing?

Decently, there are tons of documentation on how to do this on the ORMLite website. Here's a section in the query builder .

I'm not sure what you mean by “full query”, but your example will work with some settings:

List <...> results = newDao.queryBuilder (). where (). eq ("name", valueofname) .query ();

It makes no sense to simply return the name, because the Tao hierarchy is designed to return a specific Client object. If you just need a name, you can specify a column of names only for return:

... clientDao.queryBuilder (). selectColumns ("name"). where () ...

This will return a list of Client objects with only a name field (and an id field, if one exists) retrieved from the database.

If you just need name strings, you can use the RawResults function.

+27
source share

All Articles