Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
So, Let's say:-

Post () method-
String a = request.getParameter("FirstName");
String b = request.getParameter("LastName");

Now, stored procedure expects three parameters:-
a. firstname
b. lastname
c. Details - xml datatype

mystmt = conn.prepareCall("{call p_addeditcustomer(?,?,?)});
mystmt.setString("FirstName",a);
mystmt.setString("LastName",b);
mystmt.setString("Details",details);
mystmt.executeQuery();
Now here is the problem this is what the details parameter expects in xml format

details-
<Table1>
<FirstName>a</FirstName>
<LastName>b</LastName>
</Table1>
How do I convert the above fields into that xml string and pass it to the stored procedure please help me out? I am a beginner in JSP and servlets.


What I have tried:

I have tried to convert the string to xml string and pass it to the stored procedure but it dint work
C#
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
             DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

             Document doc = docBuilder.newDocument();
             Element rootElement = doc.createElement("Table1");
             doc.appendChild(rootElement);

              Element firstname = doc.createElement("CustomerID");
              firstname.appendChild(doc.createTextNode("19165070951"));
              rootElement.appendChild(firstname);

             TransformerFactory transformerFactory = TransformerFactory.newInstance();
             Transformer transformer = transformerFactory.newTransformer();
             DOMSource source = new DOMSource(doc);
             StreamResult result = new StreamResult(System.out);
             transformer.transform(source, result);
             String d = result.toString();

I tried passing d to the stored procedure but it refused to work.
Posted
Comments
CHill60 12-Nov-16 21:09pm    
"refused to work" ... so your error message was "I refuse to do this!"? I don't think so. Describe the actual problem and we may be able to help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900