Java Code Examples for org.sql2o.Query#executeAndFetchTable()
The following examples show how to use
org.sql2o.Query#executeAndFetchTable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Sql2oIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void whenFetchTable_thenResultsAreMaps() { Sql2o sql2o = new Sql2o("jdbc:hsqldb:mem:testDB", "sa", ""); try(Connection connection = sql2o.open()) { connection.createQuery("create table PROJECT_5 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100), creation_date date)").executeUpdate(); connection.createQuery("INSERT INTO PROJECT_5 (NAME, URL, creation_date) VALUES ('tutorials', 'github.com/eugenp/tutorials', '2019-01-01')").executeUpdate(); connection.createQuery("INSERT INTO PROJECT_5 (NAME, URL, creation_date) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring', '2019-02-01')").executeUpdate(); Query query = connection.createQuery("select * from PROJECT_5 order by id"); Table table = query.executeAndFetchTable(); List<Map<String, Object>> list = table.asList(); assertEquals("tutorials", list.get(0).get("name")); assertEquals("REST with Spring", list.get(1).get("name")); connection.createQuery("drop table PROJECT_5").executeUpdate(); } }
Example 2
Source File: Sql2oIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void whenFetchTable_thenResultsAreRows() { Sql2o sql2o = new Sql2o("jdbc:hsqldb:mem:testDB", "sa", ""); try(Connection connection = sql2o.open()) { connection.createQuery("create table PROJECT_5 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100), creation_date date)").executeUpdate(); connection.createQuery("INSERT INTO PROJECT_5 (NAME, URL, creation_date) VALUES ('tutorials', 'github.com/eugenp/tutorials', '2019-01-01')").executeUpdate(); connection.createQuery("INSERT INTO PROJECT_5 (NAME, URL, creation_date) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring', '2019-02-01')").executeUpdate(); Query query = connection.createQuery("select * from PROJECT_5 order by id"); Table table = query.executeAndFetchTable(); List<Row> rows = table.rows(); assertEquals("tutorials", rows.get(0).getString("name")); assertEquals("REST with Spring", rows.get(1).getString("name")); connection.createQuery("drop table PROJECT_5").executeUpdate(); } }