I'm trying to implement java method for web service that should retrieve data from table and return the result in json format. For this I use json_agg() function that converts query result into json which I want to display, but it displays in wrong format so far. Here is the method itself:
public String GetRowsFromTable() throws SQLException {
Connection connection = null;
String result = "";
try {
connection = Connection.getConnection();
PreparedStatement prepStmt = conn.prepareStatement("SELECT json_agg(table1) FROM table");
ResultSet rs = prepStmt.executeQuery();
result += rs;
System.out.println(rs);
} catch (SQLException sqlex) {
sqlex.printStackTrace();
} finally {
connection.close();
}
return result;
}
The console displays the following result:
org.postgresql.jdbc.PgResultSet@5179f609
Any help would be appreciated.