my jsp code
Expand|Select|Wrap|Line Numbers
- <%@ page import="java.sql.*" %> <%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> <HEAD> <TITLE>Fetching Data From a Database</TITLE> </HEAD> <H1>Fetching Data From a Database</H1> <%
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/tree","root","admin321");
- Statement statement = con.createStatement();
- String id = request.getParameter("name");
- ResultSet resultset =
- statement.executeQuery("select * from bitab") ;
- if(!resultset.next()) {
- out.println("Sorry, could not find . ");
- } else {
- %> <%
- }
- %>
- [
- <% while (resultset.next()) { %>
- { "name": "<%= resultset.getString("parent") %>" , "children": [{ "name": "<%= resultset.getString("child1") %>"},
- "children": [{ "name": "<%= resultset.getString("child2") %>"},
- { "name": "<%= resultset.getString("child3") %>"} ,
- "children": [{ "name": "<%= resultset.getString("child4") %>"}
- ] },
- ] },
- ]},
- ]
- <% } %> ;
can anyone suggest me a way to get the json as below
Expand|Select|Wrap|Line Numbers
- {
- "name":"par1",
- "children":[
- {
- "name":"chil 1",
- "children":[
- {
- "name":"chil 11"
- },
- {
- "name":"chil 12"
- },
- {
- "name":"chil 2",
- "children":[
- {
- "name":"chil 21"
- },
- {
- "name":"chil 22"
- }
- ]
- }
- ]
- }
- ]
- }