473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Mysql data into JSON using JSP

i am trying to get data from the mysql table in JSON format..

my jsp code
Expand|Select|Wrap|Line Numbers
  1.  <%@ 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> <% 
  2.              Class.forName("com.mysql.jdbc.Driver");  
  3.  
  4.       Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/tree","root","admin321"); 
  5.  
  6.  
  7.             Statement statement = con.createStatement();
  8.  
  9.             String id = request.getParameter("name");  
  10.  
  11.             ResultSet resultset = 
  12.                statement.executeQuery("select * from bitab") ; 
  13.  
  14.             if(!resultset.next()) {
  15.                 out.println("Sorry, could not find . ");
  16.             } else {  
  17.         %> <% 
  18.            } 
  19.        %>
  20.        [
  21.  
  22.          <% while (resultset.next()) { %> 
  23.  
  24.   { "name": "<%= resultset.getString("parent") %>" ,   "children": [{ "name": "<%= resultset.getString("child1") %>"},
  25.  
  26.     "children": [{ "name": "<%= resultset.getString("child2") %>"},
  27.    { "name": "<%= resultset.getString("child3") %>"}   ,
  28.      "children": [{ "name": "<%= resultset.getString("child4") %>"}
  29.     ] },
  30.              ] },
  31.                              ]},
  32.                              ]
  33.  
  34.  
  35.  <% } %> ;
  36.  
i cant able to get correct json format and also the null values includes as child in json..any suggestions would be helpfull..
can anyone suggest me a way to get the json as below
Expand|Select|Wrap|Line Numbers
  1. {  
  2.    "name":"par1",
  3.    "children":[  
  4.       {  
  5.          "name":"chil 1",
  6.          "children":[  
  7.             {  
  8.                "name":"chil 11"
  9.             },
  10.             {  
  11.                "name":"chil 12"
  12.             },
  13.             {  
  14.                "name":"chil 2",
  15.                "children":[  
  16.                   {  
  17.                      "name":"chil 21"
  18.                   },
  19.                   {  
  20.                      "name":"chil 22"
  21.                   }
  22.                ]
  23.             }
  24.          ]
  25.       }
  26.    ]
  27. }
Dec 30 '16 #1
0 3113

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AMD | last post by:
Hi, I would like to have MySQL use a mapped network drive. I'd like to do this in case there is a failure of the mysql machine, I can just replace it with a new machine pointing to the same...
3
by: jonas | last post by:
Guys was wondering has any done this I need to get a heads up as i need to grab data from a databasemake some changes and then put it back in place I'm guessing the MySqlDB Module be it seems...
1
by: im2kul2 | last post by:
I'd be GREATLY APRECIATED if someone could bail me out of this one! I logged into my server an hour ago just to find that the root partition is 100% filled: /dev/mapper/VolGroup00-LogVol00...
2
by: Bill | last post by:
Hi, I try to connect to Mysql using the Mysql Connector 1.0.7. with asp.net 2.O. In "mysql.aspx", i put: <%@ import namespace="System.Data"%> <%@ Import Namespace = "MySql.Data.MySqlClient"...
4
by: Brian Huether | last post by:
My webhost does not give me shell access. Normally, I use this sort of command on my local machine: c:\datac:\mysql\bin\mysql -uroot -pxxxxx db < file.sql My webhost gives me PhpMyAdmin...
1
by: Carmine [www.thetotalsite.it] | last post by:
Hi, I am using ASP.Net 2.0 with the MySQL Connector .Net 5.1.2.2. I added these lines to the web.config to make the connector.net able to handle the SqlConnection object (and so to bind it to a...
3
by: crocodilu2008 | last post by:
Why this not working ? Our SQL table. username email tommy tommy@example.com jane jane@example.com jack jack@example.com
5
semanticnotion
by: semanticnotion | last post by:
i have retrieved mysql data from one table in json using the following script $table_first = 'abc'; $query = "SELECT * FROM $table_first"; $resouter = mysql_query($query, $conn); $set =...
4
semanticnotion
by: semanticnotion | last post by:
hi i have 3 tables in mysql i retrieved the data in xml using php now i want to retrieved the same data in json format but i have some problem in queries. i retrieved data from one table in json but...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.