Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31731

Can we convert a Java ResultSet/SqlRowSet from Database query directly to JSON array without Mapping it to a List<Type>?

Newsgroups comp.lang.java.programmer
Date 2015-05-22 01:21 -0700
Message-ID <434cb251-ceeb-4a60-8205-caa8c8b7087f@googlegroups.com> (permalink)
Subject Can we convert a Java ResultSet/SqlRowSet from Database query directly to JSON array without Mapping it to a List<Type>?
From kaushal patel <kpt1991@gmail.com>

Show all headers | View raw


String sql = "select employee_id,first_name,last_name,email,salary from employees";

SqlRowSet  employees = null ;

try{
  employees = jdbcTemplate.queryForRowSet(sql);
}
catch(Exception e)
{
  e.printStackTrace();	
}
return employees ;

I want to know if there is any library present that can convert it to JSON.

I have tried with google GSON Library and Jackson Library but both requires first extraction of column to Type Class like Employee in this case.

If I am able to do this it can provide me a dynamic nature on my frontend like once we have 3 columns on frontend then we want 4 u just have to edit the query.

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Can we convert a Java ResultSet/SqlRowSet from Database query directly to JSON array without Mapping it to a List<Type>? kaushal patel <kpt1991@gmail.com> - 2015-05-22 01:21 -0700
  Re: Can we convert a Java ResultSet/SqlRowSet from Database query directly to JSON array without Mapping it to a List<Type>? Arne Vajhøj <arne@vajhoej.dk> - 2015-05-22 21:15 -0400

csiph-web