Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa XML retrieving xml document from database
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


madhusudhan
retrieving xml document from database
1 Answer(s)      2 years and 9 months ago
Posted in : XML


Hi Guys, I want to retrieve the xml document stored in the database on to a jsp page using jdbc/odbc connnection.Please help me in implementing this feature.

Thank You Madhu


Advertisement
View Answers

March 5, 2012 at 10:59 AM


import java.io.*;
import java.sql.*;

import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class JavaXmlDataBase{
public static void main(String args[]) throws IOException {

try
{
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
//creating a new instance of a DOM to build a DOM tree.
Document doc = docBuilder.newDocument();
new XmlServlet().createXmlTree(doc);

System.out.println("<b>Xml File Created Successfully</b>");
}
catch(Exception e)
{
System.out.println(e);
}


}

public void createXmlTree(Document doc) throws Exception {
//This method creates an element node
Element root = doc.createElement("Company");
//adding a node after the last child node of the specified node.
doc.appendChild(root);

Element child = doc.createElement("Location");
root.appendChild(child);


Element child1 = doc.createElement("Companyname");
child.appendChild(child1);

Text text = doc.createTextNode("Roseindia.Net");
child1.appendChild(text);

Comment comment = doc.createComment("Employee in roseindia");
child.appendChild(comment);


Connection con = null;
int count = 0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con=DriverManager.getConnection("jdbc:odbc:college");
try{
String sql = "SELECT * FROM employee_details";
PreparedStatement prest = con.prepareStatement(sql);


ResultSet rs = prest.executeQuery();
Element element=null;
Text text1=null;
while (rs.next()){
String name = rs.getString(2) + " " + rs.getString(3);

element = doc.createElement("Employee");
child.appendChild(element);

text1 = doc.createTextNode(name);
element.appendChild(text1);
count++;
}
prest.close();
con.close();
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}


Related Tutorials/Questions & Answers:
retrieving xml document from database
retrieving xml document from database  Hi Guys, I want to retrieve the xml document stored in the database on to a jsp page using jdbc/odbc connnection.Please help me in implementing this feature. Thank You Madhu
Retrieving attribute value from XML
Retrieving attribute value from XML  I have an XML as below to parse...-values-from-a-nodel.shtml http://www.roseindia.net/xml/dom/GetData.shtml Thanks...(); is.setCharacterStream(new StringReader(xmlRecords)); Document doc = db.parse
Advertisements
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
related retrieving value from oracle database
related retrieving value from oracle database  how we get the value from database in the given textbox
Retrieving the Image from a database Table
Retrieving the Image from a database Table Consider a case where we want... to retrieve the image from the database table. You can do it very easily after... from the database table our java program need to make a connection
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am new to jsp.In my applcation i having a problem. I am retrieving user payment from... information from database the i want to show cash radio button checked.How can i do
Retrieving Data from Database to fill Combo Box
Retrieving Data from Database to fill Combo Box  Sir, I have a JSP Page with a combo box and a label. I have a database that has two fields id... displaying path that is stored in the database but not the image itself. Kindly
Retrieving value from multiple table in database
Retrieving value from multiple table in database  Hi fnds, I want to maintain the financial database of 20 users for 1 year and update the details... FROM ( SELECT * FROM month1 UNION ALL SELECT * FROM month2 UNION ALL
Remove Element from XML Document
Remove Element from XML Document     ... a given  XML document. Whenever you remove the xml element from the xml document... element from the XML document by  invoking the getParentNode() method . Here
Retrieving Data From the XML file
Retrieving Data From the XML file  ... is only geared towards showing how to construct a Java object from an XML document.  By this example we are going to get the XML data from the xml file in our
Retrieving JTree structure from database
Retrieving JTree structure from database       This example shows how to retrieving data from... the steps required to create tree retrieving the data from the database. Here
retrieving newly added records from mssql database and display in a jsp
retrieving newly added records from mssql database and display in a jsp ... from mssql database table and display those records in a jsp.And i have to delete these 10 records from the jsp and retrieve the next recently added 10 records
Retrieving Information From Database in JSF Framework - Development process
Retrieving Information From Database in JSF Framework  Requirement... retrieved from database. see how the datatable in select.jsp should be http......... and the connection to database should use via datasource please answer
java code to create xml document from DOM object
java code to create xml document from DOM object  Hey! After knowing the way we can create DOM objects and add elements to it-> then displaying it on the console ;is there a way I can output the same in xml document
how to check dates while retrieving data from database
how to check dates while retrieving data from database  i want to update database record based on delivery date i have tried this query but it wont work b="update deliveryorder set prtnm='"+arr[1]+"',stn='"+arr[0]+"',sbston
The code for retrieving data from database into Drop Down List.
The code for retrieving data from database into Drop Down List.  <... to MySQL"); PreparedStatement pre = con.prepareStatement("select * from... = con.prepareStatement("select Quantity from library.booklist where Book = ? "); result
graph generation using jfreechart and retrieving values from the database
graph generation using jfreechart and retrieving values from the database  I have made a database containing 4 subject marks and name and roll no. of students.The dsn name is chartdsn. I want to retrieve the data from the access
Getting Data from XML File (Document)
Getting Data from XML File (Document)   ...: This program helps you in retrieving the data from a XML file. It takes a xml file... to the output . Here the results are displayed at the console from the XML document
retrieving data from database to the textbox depending upon the id in jsp
retrieving data from database to the textbox depending upon the id in jsp  Hi, our project involves fetching of data from database into textbox... will be checked to database weather it exist or not and if it exists
retrieving data in to the dropdown box from postgresql database in core java
retrieving data in to the dropdown box from postgresql database in core...=st.executeQuery("SELECT role_name from role WHERE dept_id=1234"); if(rs... database: import java.sql.*; import java.awt.*; import javax.swing.*; import
xml document parsing
xml document parsing   Hi Guys, Xml document has been inserted into the database,how do i parse the xml document stored in database,so that xml document can be retrieved on to JSP file using jdbc/odbc connection. Please help me
retrieving from oracle database using jsp combo box
retrieving from oracle database using jsp combo box  hi this is my... name of the server has to display in the process name field from the oracle database please help on this i need code using servlets please help me . <
creating document in XML - XML
creating document in XML  Create an XML document for catalogue...)); System.out.print("Enter number to add elements in your XML file: "); String... = documentBuilderFactory.newDocumentBuilder(); Document
Storing Data (Retrieved from a XML Document) to a File
Storing Data (Retrieved from a XML Document) to a File... to store data (retrieved from the XML document) to a specified file (with ... retrieved from the xml document.  An object of Document is passed
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  hi all, how can i insert elements into java script list box retrieving from Database. whenever I insert any element in the Db
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc  how to make a radio button selected when retrieving data from database using struts framework and spring jdbc
how to insert list box in java script dynamically and elements retrieving from database like oracle
how to insert list box in java script dynamically and elements retrieving from database like oracle  Hi, how to dynamically increase size of list box in javascript when elements retrieving from database.. That is whenever I
How to store extracted values from xml in a database? - XML
How to store extracted values from xml in a database?  I want to store extracted xml values in a database... How can i store extacted xml values in a database... give me a example
How to store extracted values from xml in a database? - XML
How to store extracted values from xml in a database?  I want to store extracted xml values in a database... How can i store extacted xml values in a database... give me a example
Retrieving Tables from a Database
Retrieving Tables from a Database       In database system it is very important to know about... for retrieving tables from a specific database through an example. In relational
data insertion from xml file to database table
data insertion from xml file to database table  Hi all, I have data in the XML file. I need to insert it into table in the database using servlet. so please reply me . ThankYou
Advertisements
 

 

 

DMCA.com