Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. |_child (column 2)
  2.  
  3. |_sub-child (column 3)
  4.  
  5. package JAVA;
  6. import java.util.List;
  7.  
  8. public class json {
  9.  
  10.  
  11. private String parent;
  12.  
  13. private List<String> child1;
  14. private List<String> child2;
  15.  
  16.  
  17. public String getparent() {
  18. return parent;
  19. }
  20. public void setparent(String parent) {
  21. this.parent =parent;
  22. }
  23.  
  24. public List<String> getchild1() {
  25. return child1;
  26. }
  27. public void setchild1(List<String> child1) {
  28. this.child1 = child1;
  29. }
  30. public List<String> getchild2() {
  31. return child2;
  32. }
  33. public void setchild2(List<String> child2) {
  34. this.child2 = child2;
  35. }
  36.  
  37. }
  38.  
  39. package JAVA;
  40.  
  41. <%@page import="java.util.List"%>
  42. <%@page import="java.util.ArrayList"%>
  43. <%@page import="com.google.gson.GsonBuilder"%>
  44. <%@ page import="java.sql.*" %>
  45. <%@page pageEncoding=
  46. "UTF-8" contentType="text/html; charset=UTF-8"%>
  47. <%@ page import="jj.j1"%>
  48. <%@ page import="com.google.gson.Gson" %>
  49. <H1>Fetching Data From a Database</H1>
  50.  
  51. <%
  52. Class.forName("com.mysql.jdbc.Driver");
  53.  
  54. Connection con=DriverManager. getConnection
  55. ("jdbc:mysql://localhost:3306/tree","root","admin321");
  56.  
  57.  
  58. Statement statement = con.createStatement();
  59. ResultSet resultset =
  60. statement.executeQuery("select * from tab") ;
  61. if(!resultset.next()) {
  62. out.println("Sorry, could not find . ");
  63. } else {
  64. %>
  65.  
  66. <%
  67. }
  68. %>
  69.  
  70.  
  71. <% resultset.getString(1) ; %>
  72. <%
  73.  
  74. j1 obj = new j1();
  75.  
  76. List<String> child1 = new ArrayList<String>() ;
  77. while(resultset!=null){
  78. }
  79. {
  80.  
  81. child1.add(resultset.getString(2));
  82. out.println(child1);
  83. }
  84. List<String> child2 = new ArrayList<String>() ;
  85. while(resultset!=null){
  86. }
  87. {
  88. child2.add(resultset.getString(3));
  89. out.println(child2);
  90. }
  91. }
  92.  
  93. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement