How to return records from database using javalite?

kittu

I am using the following line to query the DB:

List<PostsCategories> postsCategories = PostsCategories.findBySQL("select category from posts_categories");

Instead of returning only [{category=Miscellaneous},....] it is returning extra info such as Model, table, attributes inside array.

I don't know why it works this way with activejdbc?

[Model: com.ngo.org10s.models.PostsCategories, table: 'posts_categories', attributes: {category=Miscellaneous}]

How do I simply return the required values?

ipolevoy

It is because ActiveJDBC is an ORM == Object Relational Mapping. This means that a model instance contains all attributes to represent a single row in the table.

The method findBySQL has JavaDoc that states:

Ensure that the query returns all columns associated with this model, so that the resulting models could hydrate themselves properly

In other words, if an instance of a PostsCategories has just one attribute set, than this is not an ORM anymore.

If you insist on getting just one attribute, use org.javalite.activejdbc.Base:

List<Map> categories = Base.findAll("select category from posts_categories");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to find index of array of records return from database in rails?

From Dev

Return only repeated records from database

From Dev

How to delete records from database using checkbox and button which are not in the form

From Dev

How to fetch records from the database using Play with Scala and Slick

From Dev

How to display records from a Firebase database using HashMap<String, String>?

From Dev

How to return all records that were added to the database within the last 7 days from current date

From Dev

Using Date functions to pull records from database

From Dev

How to return no records found from a stored procedure

From Dev

How to return all records from all tables?

From Dev

how to delete records from database with an Ajax

From Dev

How to use two different records from database?

From Dev

laravel : how to filter records from database side

From Dev

How can I get limited records from database using spring JPA?

From Dev

How to save multiple database records from several views in MVC 4 using EF?

From Dev

Return a result from a database using Entity Framework

From Dev

How to return data from the database using 3 tier architecture structure using ASP.NET C#

From Dev

Deleting all table records from core data database using relationship

From Dev

SQL Trouble using DATEADD to delete records from database

From Dev

Select records from a SQL Server database using geography and distance

From Dev

Retrieve only today records from MySQL database using PHP

From Dev

How to return a null value from a database

From Dev

How to return last record from database in codeigniter?

From Dev

How to return a single value from a database?

From Dev

How to return one variable from database?

From Dev

How to return a null value from a database

From Dev

How to return array from database in c#

From Dev

Laravel - How to store a return from a function to the database?

From Dev

How to return random records in Neo4j using Cypher?

From Dev

How to return the count of records using a user defined function in SQL?

Related Related

  1. 1

    How to find index of array of records return from database in rails?

  2. 2

    Return only repeated records from database

  3. 3

    How to delete records from database using checkbox and button which are not in the form

  4. 4

    How to fetch records from the database using Play with Scala and Slick

  5. 5

    How to display records from a Firebase database using HashMap<String, String>?

  6. 6

    How to return all records that were added to the database within the last 7 days from current date

  7. 7

    Using Date functions to pull records from database

  8. 8

    How to return no records found from a stored procedure

  9. 9

    How to return all records from all tables?

  10. 10

    how to delete records from database with an Ajax

  11. 11

    How to use two different records from database?

  12. 12

    laravel : how to filter records from database side

  13. 13

    How can I get limited records from database using spring JPA?

  14. 14

    How to save multiple database records from several views in MVC 4 using EF?

  15. 15

    Return a result from a database using Entity Framework

  16. 16

    How to return data from the database using 3 tier architecture structure using ASP.NET C#

  17. 17

    Deleting all table records from core data database using relationship

  18. 18

    SQL Trouble using DATEADD to delete records from database

  19. 19

    Select records from a SQL Server database using geography and distance

  20. 20

    Retrieve only today records from MySQL database using PHP

  21. 21

    How to return a null value from a database

  22. 22

    How to return last record from database in codeigniter?

  23. 23

    How to return a single value from a database?

  24. 24

    How to return one variable from database?

  25. 25

    How to return a null value from a database

  26. 26

    How to return array from database in c#

  27. 27

    Laravel - How to store a return from a function to the database?

  28. 28

    How to return random records in Neo4j using Cypher?

  29. 29

    How to return the count of records using a user defined function in SQL?

HotTag

Archive