473,549 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Store query result in a xml file

5 New Member
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 3302
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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
3908
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 column table names. I know that there are codes to generate tabs and carriage returns, but can't find anything about including "commas" in a string...
3
2328
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 retieves the values perfectly. This form is being used to update the record in the table via a successconfirmation.asp. Now, when the checkbox is loaded...
31
10285
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 value c. Now, I want to obtain the difference between the two, that is, the value c. Which type must I use for c? I searched around and did not...
1
2582
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. Every dealer reports several customers and I have today a query that sorts out how many customer data each BMW dealer sends in to us. The query is also...
1
1739
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 members.email from members, filestorage where filestorage.author = members.username and FileID = {$id}" ; then execute the query using command...
2
5303
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
8606
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
2303
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 files has raw data. Before the final output , many calculations are being done. I have been told to debug.
25
7387
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 user specifies so no label is printed in that particular place. I am aware of the problems of inserting blank records to tables. I say this as the...
0
7532
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7730
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7971
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7491
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5381
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1068
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.