How to convert a String data type to XML format in Java? -


i working on web application , values capture form passed stored procedure. now, 1 of parameters of stored procedure accepts xml string. parameter called "detailold" , have no clue how convert string values form xml string. can please me out?

@override     protected void dopost(httpservletrequest request, httpservletresponse response)             throws servletexception, ioexception {        // processrequest(request, response);         printwriter out1 = response.getwriter();          out1.println("hey");         try {             // processrequest(request, response);             out1.println("servlet ");             class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver");         } catch (classnotfoundexception ex) {             logger.getlogger(connectioncheck.class.getname()).log(level.severe, null, ex);         }         connection conn = null;                 preparedstatement mystmt = null;                 int num = -1;          try {             conn = drivermanager.getconnection("jdbc:sqlserver://mpesa\\sql2012;user=realm;password=friend;database=elmatest");             if(conn!=null)             {                 out1.print("connection succesful");                try{                     mystmt = conn                     .preparestatement("exec p_addeditaccountcustomer ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?");                  if(mystmt!=null)                 {                string mnumber = request.getparameter("mobilenumber");                 string mtitle = request.getparameter("title");                  string fname= request.getparameter("firstname");                 string mname = request.getparameter("middlename");                 string lname = request.getparameter("lastname");                  string maddress = request.getparameter("address");                  string melmaid = request.getparameter("elmaid");                  string mcity = request.getparameter("city");                  string mid = request.getparameter("idtype");                  string midno = request.getparameter("idno");                  string operatorid = "1";                  string bankid = "99";                  string country = "kenya";                  string customercountry = "1";                  string maccntid = request.getparameter("accountid");                  string accounttype="1";                  string cardnumber ="1";                  string mcurrency = request.getparameter("currency");                 string branchid = "1";                 string aliasname="1";                  string createdby="1";                 string createdon ="2016-11-02";                 string detailold = "1";`//this procedure //expects xml string. have used default value 1 testing //purpose.`                 string detailnew = "1";                 string moduleid="2001";                 string eventid="1";                 mystmt.setstring(1, mnumber);                 mystmt.setstring(2, mtitle);                 mystmt.setstring(3, fname);                 mystmt.setstring(4, mname);                 mystmt.setstring(5, lname);                 mystmt.setstring(6, maddress );                 mystmt.setstring(7, melmaid);                 mystmt.setstring(8,mcity);                 mystmt.setstring(9, mid );                 mystmt.setstring(10, midno);                 mystmt.setstring(11,operatorid );                 mystmt.setstring(12, bankid );                 mystmt.setstring(13, country);                 mystmt.setstring(14, customercountry );                 mystmt.setstring(15, maccntid);                 mystmt.setstring(16, accounttype);                 mystmt.setstring(17, cardnumber);                 mystmt.setstring(18, mcurrency);                 mystmt.setstring(19, branchid);                 mystmt.setstring(20,aliasname );                 mystmt.setstring(21, createdby);                 mystmt.setstring(22,createdon);                 mystmt.setstring(23, detailold);                 mystmt.setstring(24, detailnew );                 mystmt.setstring(25, moduleid);                 mystmt.setstring(26,eventid);                 mystmt.executequery();                  }                }catch (sqlexception exc) {                   exc.printstacktrace();         } {                     //out1.println("done properly");                    response.sendredirect("customerdetails.jsp");                      mystmt.close();                   conn.close();         }                                }          }  catch (sqlexception ex) {             logger.getlogger(connectioncheck.class.getname()).log(level.severe, null, ex);         }       } 

xml format- string detailold-

<table1>   <customerid>1916507095</customerid>   <accounttype>bank</accounttype>   <country>kenya</country>   <bankid>99</bankid>   <bankaccountid>001001000095</bankaccountid>   <titleofaccount>mr</titleofaccount>   <firstname>pramod1</firstname>   <middlename>kb1</middlename>   <lastname>sahoo</lastname>   <branchid>000</branchid>   <typeofid>driving license</typeofid>   <idnumber>276999</idnumber>   <emailid>pramodk@cs.com</emailid>   <address>nairobi</address>   <city>awendo</city>   <cardnumber>kenya</cardnumber>   <currencyid>kes</currencyid>   <aliasname>pramod</aliasname> </table1> 

  1. you can create java class getter setter (pojo) - detailold.java
  2. populate pojo object data getting database in loop.
  3. convert object xml using jaxb

here 1 example how convert data xml using jaxb - https://www.mkyong.com/java/jaxb-hello-world-example/


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -