473,399 Members | 3,106 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,399 software developers and data experts.

Store query result in a xml file

5
I want to store the query result, in an servlet, into an xml file and display the contents of the xml file on the browser......

my code is as follows:

Expand|Select|Wrap|Line Numbers
  1. public void doPost(HttpServletRequest request, HttpServletResponse response)
  2.                                    throws ServletException,IOException{
  3. //      List dataList = new ArrayList();
  4.       response.setContentType("text/html");
  5.     PrintWriter pw = response.getWriter();
  6.  
  7.    String contextPath = request.getContextPath();
  8.    HttpSession session = request.getSession(true);
  9.  
  10.  String branchId = null;
  11.  String orgId = null;
  12.  String stateId = null;
  13.  String regionId = null;
  14.  String lot_ref="";
  15.  String lot_wt="";
  16.  String item="";
  17.  
  18.  
  19.  
  20.  
  21.   PrintWriter out = response.getWriter();
  22.     //Establish connection to MySQL database
  23.      String url="jdbc:mysql://192.168.1.3:3306/APMC?user=apmc&password=apmc";
  24.     Connection con = null;
  25.     ResultSet rs=null;
  26.     Statement st=null;
  27.     try {
  28.  
  29.  
  30.        Class.forName("com.mysql.jdbc.Driver").newInstance();
  31.        System.out.println("driver regristration success!");
  32.        con=DriverManager.getConnection(url);
  33.        System.out.println("connected tendring............     ");
  34.  
  35.       String sql = "select SQL_CALC_FOUND_ROWS lot.n_lot_ref_no,bidact.c_item_name,"+
  36.                             " bidact.m_lot_wieght FROM t_bidding_activation bidact, t_lot_master lot, t_stakeholder_master stakeholder"+
  37.                            " where bidact.c_active='Y' and "+
  38.                             "bidact.n_lot_id=lot.n_lot_id and stakeholder.n_stakeholder_id=lot.n_stakeholder_id  and bidact.c_bidded!='Y'"+
  39.                             "and bidact.c_branch_id='" + branchId + "' and bidact.c_org_id='"+ orgId +"' and bidact.c_state_id='" + stateId + "' "+
  40.                             "and bidact.c_region_id='" + regionId + "'  order by bidact.c_item_name,"+
  41.                             "bidact.d_bid_end_date, bidact.d_bid_end_time";
  42.  
  43. System.out.println("Output from dopost..........................");
  44. System.out.println("after query..................................");
  45.       st = con.createStatement();
  46.       st.executeQuery (sql);
  47.       rs = st.getResultSet();
  48.       System.out.println("result" +rs);
  49.  
  50.       System.out.print("before while");
  51.       while (rs.next()){
  52.         //Add records into data list
  53.           System.out.println("Hello....................................");
  54.         lot_ref= rs.getString(1);
  55.         System.out.print("refnum"+lot_ref);
  56.         lot_wt=rs.getString(2);
  57.        System.out.print("lotwt"+lot_wt);
  58.         item= rs.getString(3);
  59.        System.out.print("item"+item);
  60. //       dataList.add(rs.getString("lot.n_lot_ref_no"));
  61. //        dataList.add(rs.getString("bidact.c_item_name"));
  62. //        dataList.add(rs.getString("bidact.m_lot_wieght"));
  63.  
  64.  
  65.       }
  66. System.out.print("after while");
  67.  
  68.  
  69.  
  70.  
  71.       }catch(Exception e){
  72.       System.out.println("Exception is ;"+e);
  73.       }
  74.  
  75.  
  76.  
  77.   /*if(request.getParameter("strUserName")!=null && request.getParameter("strPassword")!=null)
  78.     {
  79.         String username = request.getParameter("strUserName").toString();
  80.        String passwd = request.getParameter("strPassword").toString();
  81.     }*/
  82.     // if (uName.equals(userName) && passwd.equals(password)){
  83.  
  84.   try
  85.   {
  86.     DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
  87.         DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
  88.         //creating a new instance of a DOM to build a DOM tree.
  89.         Document doc = docBuilder.newDocument();
  90.         new xmlServlet().createXmlTree(doc,lot_ref, lot_wt,item);
  91.  
  92.  
  93.     pw.println("<b>Xml File Created Successfully</b>");
  94.   }
  95.   catch(Exception e)
  96.   {
  97.     System.out.println(e);
  98.   }
  99.     try{
  100.     rs.close ();
  101.       st.close ();
  102.       con.close();
  103.     }catch(Exception e){
  104.       e.printStackTrace();
  105.     }
  106.     /* }
  107.      else
  108.      {
  109.      System.out.println("Invalid User");
  110.      }*/
  111.  
  112.   }
  113.  
  114.   public void createXmlTree(Document doc, String lot_ref, String lot_wt, String item) throws Exception {
  115.         //This method creates an element node
  116.         Element root = doc.createElement("User");
  117.         //adding a node after the last child node of the specified node.
  118.         doc.appendChild(root);
  119.  
  120.  
  121.  
  122.         Element child1 = doc.createElement("lot_ref");
  123.         root.appendChild(child1);
  124.  
  125.         Text text = doc.createTextNode(lot_ref);
  126.         child1.appendChild(text);
  127.  
  128.  
  129.  
  130.         Element element = doc.createElement("lot_wt");
  131.         root.appendChild(element);
  132.  
  133.         Text text1 = doc.createTextNode(lot_wt);
  134.         element.appendChild(text1);
  135.  
  136.         Element element1 = doc.createElement("item");
  137.         root.appendChild(element1);
  138.  
  139.         Text text2 = doc.createTextNode(item);
  140.         element.appendChild(text2);
  141.  
  142.  
  143.  
  144.  
  145.      //TransformerFactory instance is used to create Transformer objects.
  146.         TransformerFactory factory = TransformerFactory.newInstance();
  147.         Transformer transformer = factory.newTransformer();
  148.  
  149.         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  150.  
  151.  
  152.         // create string from xml tree
  153.         StringWriter sw = new StringWriter();
  154.         StreamResult result = new StreamResult(sw);
  155.         DOMSource source = new DOMSource(doc);
  156.         transformer.transform(source, result);
  157.         String xmlString = sw.toString();
  158.  
  159.         File file = new File("c:/temp/tender.xml");
  160.         BufferedWriter bw = new BufferedWriter
  161.                       (new OutputStreamWriter(new FileOutputStream(file)));
  162.         bw.write(xmlString);
  163.         bw.flush();
  164.         bw.close();
  165.  
  166.     }
  167.  
  168.  
  169. }
Here I am able to create a xml file ... but i need to use some array ... to store large number of data... which i am not able to do.....
could u help me regarding this,
once i do tat ... i need to display the content of the xml file in the browser.

regards,
reebeca
Mar 24 '10 #1
2 3289
Dheeraj Joshi
1,123 Expert 1GB
First of all, you have posted your question in the wrong place.

Have you tried to code? What problem you are getting?

Regards
Dheeraj Joshi

* When i was typing this question Dormilich moved this thread
Mar 24 '10 #2
jkmyoung
2,057 Expert 2GB
It seems you can create each row in the while(rs.next()) loop. Why not add your nodes there? Have a function kind of like createXmlTree(), say instead createXMLBranch(), and add the node created to your main document node.

Also, let's focus on making the xml file before you get caught up in display.
Mar 25 '10 #3

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

Similar topics

2
by: Joe Gazda | last post by:
I'm a relative newbie to PHP, but have been able to put together some PHP code to generate a CSV/XLS file from a Query result. Now, I would like to include custom column names instead of the MySQL...
3
by: Jack | last post by:
Hi, I have a form when loaded, retrieves record from an access table. Among other fields there is a check box called FinalUpdate. This is tied to a field in Access of type Yes/No. The form...
31
by: Spiro Trikaliotis | last post by:
Hello, I have a question regarding subtracting a pointer from another one. Assume I have two pointers p1 and p2, which both point to a memory area obtained with malloc(). Assume p1 = p2 + some...
1
by: RookieDan | last post by:
Greetings fellow Accessers! Im new but in Access, but I have some background in different coding. I have a programme loading customer data into Access belonging to BMW dealers in Europe. ...
1
ddtpmyra
by: ddtpmyra | last post by:
how can I capture the query result in PHP? I have two queries below: # Fetch the file information $query ="update filestorage set approved ='Y' where FileID = {$id}"; $query1 ="select...
2
by: jatin32 | last post by:
Hi, I have to export query result to EXCEL file in certain location. how do I do that? I have used DoCmd.OutputTo acOutputQuery, stDocName, acFormatXLS, , , , , acExportQualityScreen
5
xxoulmate
by: xxoulmate | last post by:
i wanted to export the query result into csv file is there any way to do it., e.g. select field1,field2 from table into csvfile
1
by: titli | last post by:
Hi Friends, I have some code in an already built application. Now the output pivots in .xls files is not matching with input data. The output .xls has summarized results whereas , the input...
25
by: NDayave | last post by:
How do, I have a form that outputs addresses in a format that can be printed on to 3x7 label paper for envelopes. What I want is a way to enter blank (or " ") rows to the query result where the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.