Question

How can I write a query with ormlite instead of using .create or any other thing like that? Can you please show me how for this simple example :

SELECT name FROM client

EDIT since I can't answer myself : I guess I had to search a little more , anyway I found how to do it with the QueryBuilder like this :

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

If someone knows how to write the full query that would be great , otherwise , I'll stick with this solution

Was it helpful?

Solution

How can I write a query with ormlite instead of using .create or any other thing like that?

Goodness, there are tons of documentation about how to do this on the ORMLite site. Here's the section on the query builder.

I'm not sure what you mean by "full query" but your example will work with some tweaks:

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

It does not make sense to just return the name since the Dao hierarchy is designed to return the specific Client object. If you just want the name the you can specify the name column only to return:

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

That will return a list of Client objects with just the name field (and the id field if it exists) extracted from the database.

If you just want the name strings then you can use the RawResults feature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top