Share on Google+Share on Google+

geetha
xml configuration file
1 Answer(s)      7 years ago
Posted in : JDBC

Ads

View Answers

December 18, 2009 at 4:21 PM


Hi Friend,

Try the following code:

<[email protected] import="java.io.*"%>
<[email protected] import=" org.w3c.dom.*"%>
<[email protected] import=" javax.xml.parsers.*"%>
<[email protected] import=" javax.xml.transform.*"%>
<[email protected] import=" javax.xml.transform.dom.*"%>
<[email protected] import=" javax.xml.transform.stream.*"%>
<[email protected] import=" java.sql.*"%>
<%!
public void createXmlTree(Document doc,String id,String name,String address,String contactNo) throws Exception {
Element root = doc.createElement("Employee");
doc.appendChild(root);
Element element1 = doc.createElement("Emp_ID");
root.appendChild(element1);
Text text1 = doc.createTextNode(id);
element1.appendChild(text1);

Element element2 = doc.createElement("Emp_Name");
root.appendChild(element2);
Text text2 = doc.createTextNode(name);
element2.appendChild(text2);

Element element3 = doc.createElement("Emp_Address");
root.appendChild(element3);
Text text3 = doc.createTextNode(address);
element3.appendChild(text3);

Element element4 = doc.createElement("Emp_ContactNo");
root.appendChild(element4);
Text text4 = doc.createTextNode(contactNo);
element4.appendChild(text4);

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");

StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
String xmlString = sw.toString();

File file = new File("c:/employee.xml");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
bw.write(xmlString);
bw.flush();
bw.close();

}
%>
<%
response.setContentType("text/xml");

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("Select * from employee where emp_id='2'");

String id="", name="",address="",contactNo="";
while(rs.next()){
id=rs.getString("emp_id");
name=rs.getString("emp_name");
address=rs.getString("emp_address");
contactNo=rs.getString("contactNo");
}
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
createXmlTree(doc,id,name,address,contactNo);

out.println("<b>Xml File Created Successfully</b>");

}
catch(Exception e){}
%>

For more information,visit the following link:

http://www.roseindia.net/jsp/jsp-write-xml.shtml

Thanks









Related Tutorials/Questions & Answers:
xml configuration file - JDBC
xml configuration file  Hi, Could you please tell me how to write a xml configuration file . We have mysql database in some other system. I have... to create a xml file. Please help me out. Thank you  Hi Friend, Try
Configure the configuration file
Configure the configuration file  How do I configure the configuration file
Advertisements
Hibernate configuration file
This tutorial helps you in understanding the configuration file of Hibernate
Hibernate Configuration File
Hibernate Configuration File In this tutorial you will learn about the hibernate configuration file. To define a Hibernate Configuration info a resource file named hibernate.cfg.xml is used. Using this configuration file various
Hibernate Configuration File
Hibernate Configuration File In this section we will read about the hibernate configuration file. In this file we will see how we can provide the database connection information to a file. Hibernate Configuration file i.e.
What are the concepts and purpose of Spring configuration file.
What are the concepts and purpose of Spring configuration file.  Hi, What are the concepts and purpose of Spring configuration file. Thanks
More than one Faces Configuration file
More than one Faces Configuration file  Is it possible to have more than one Faces Configuration file
Creating XMl file - XML
Creating XMl file   I went on this page: http://www.roseindia.net/xml/dom/createblankdomdocument.shtml and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
xml file display - XML
xml file display   - - - - ADL SCORM CAM 1.3 - - session3 - Online Instructional Strategies that Affect Learner... code to display the above xml file in tree structure where
Sorting Xml file - XML
Sorting Xml file  I have an xml file like this: Smith USA... sort my xml file. Here is my xslt..., my ouput file will be like this: Amy AUC Bob USA John UK
splitting large xml file. - XML
splitting large xml file.  Hi, I have a large xml file(1G) and a schema (XSD) i need to split this xml to small xml files (~20M) that will be valid by the schema
parsing xml file in jsp
parsing xml file in jsp  example that pars XML file in JSP
executio of xml file
executio of xml file  how to execute xml file , on web browser
How to create XML file - XML
How to create XML file  Creating a XML file, need an example. Thanks!!  To create XML file you need plain text editor like note pad. After creating your file save it with .xml extension.  Hi,Java programming
how to read this xml file - XML
how to read this xml file  i want to read this xml file using java... read i have tried lot more , but i am not able to read this xml file...[])throws Exception { File f=new File("C:/data.xml"); DocumentBuilderFactory
Run XML file
Run XML file  Hi.. How do I execute or run an XML file? please tell me about that Thanks
xml file creation in java
xml file creation in java  how to create xml file in java so that input should not be given from keyboard. and that file should be stored.   Please visit the following links: http://www.roseindia.net/tutorial/java/xml
How to prepare XML file?
How to prepare XML file?  Hi, I want to prepare XML File, can you... you create an XML file.. Create XML File using Servlet How to generate build.xml file Complete Hibernate 3.0 and Hibernate 4 Tutorial Thanks
retrieve in xml file in struts2
retrieve in xml file in struts2  i am using struts2 and trying... can i get back the value from the xml file in the ajax function and print... properties file using ajax. i now put the values from properties file to map
Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations
Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations  how to write code to attach multiple files and upload using spring mvc 2.o with xml configuration with out annotations? please
Spring Null value, Set null value in Springs configuration file
Spring Null value, Set null value in Springs configuration file In this example you will see how to set null value in the Spring configuration file. NullBean.java package spring.nullvalue.example
questions from an xml file
questions from an xml file  i am developing online bit by bit exam for that i retrieved questions from an xml file but when i retrieved using jsp i am getting all questions at a time in a single page.but i want to show one
how to convert .xml file to csv file
how to convert .xml file to csv file  how to convert .xml file to csv file
Struts Configuration file - struts.xml
Struts Configuration file - struts.xml      .... The struts.xml File The Struts 2 Framework uses a configuration file (struts.xml... is the core configuration file for the framework and it should be present
How to convert XML file to database ?
How to convert XML file to database ?  How to convert XML file to database
how to seach a keyword in a xml file - XML
how to seach a keyword in a xml file  i have a xml file. i wanted to read and store all the tag values. i have a html form in which when i enter some keyword say "a" then it has to display the tag values starting with a letter
Store XML file into Sqlserver Database
Store XML file into Sqlserver Database  Code for storing a typical XML file into SQl server database in 1 or more tables using asp.net using C
parsing XML file to get java object - XML
parsing XML file to get java object  Hello, I'm facing a problem in parsing XML file to get the java object. I've tried to retrieve data from XML file using SAX parser. my XML file structure is the following
How to write to xml file in Java?
How to write to xml file in Java?  Hi Friends, Can anyone help me how to write in xml file in Java programming. Please fill free to give example or reference website for getting example.   Hi, To write in xml file
How to create one xml file from existing xml file's body?
How to create one xml file from existing xml file's body?  Hi, i'm working with content optimization system.I want to know how we can take all data from an xml doc's body to develope another xml with that content.I'm using JDOm
Reading a xml file - JSP-Servlet
Reading a xml file  how to read a xml file using jsp and then i have to retrive a data from that file use it in code?  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/parsing-xml.shtml
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads