473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to read data from XML file & store it in database(MySql)

Hi,

I need to get the data from XML file and store it in MySql database.
How can i do it,could you please tell me.



Regards,
KiranRredy
Dec 19 '06 #1
3 17717
hi buddy,

ref this page u ll find solution for this :

http://xml.apache.org/xerces-c/


regards

Prakash Ravindran
Dec 19 '06 #2
What techniques have you tried already? With java, there are 2 main ways of reading XML documents:

1. DOM - Document Object Model interface. This loads the XML document into main memory. With the Document Object Model, you can build documents, navigate their structure, and add, modify, or delete elements and content. Basically the DOM specifies an abstract datatype for XML logical structure. In Java the API for this is known as JAXP

http://java.sun.com/j2se/1.5.0/docs/...e-summary.html

An example of reading in a doc could be:

Expand|Select|Wrap|Line Numbers
  1. public void readDoc() {
  2.   try {
  3.  
  4.    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  5.    DocumentBuilder builder = factory.newDocumentBuilder();
  6.    doc = builder.parse( new File("myXMLFile.xml") );
  7.  
  8.   }
  9.   catch (FactoryConfigurationError fce){
  10.     System.err.println("Could not create DocumentBuilderFactory");
  11.   }
  12.   catch (ParserConfigurationException pce) { 
  13.     System.out.println("Could not locate a JAXP parser"); 
  14.   }
  15.   catch (SAXException se) {
  16.     System.out.println("XML file is not well-formed.");
  17.   }
  18.   catch (IOException ioe) { 
  19.     System.out.println(
  20.     "Due to an IOException, the parser could not read the XML file"
  21.     ); 
  22.   }
  23. }
  24.  
doc is the object which holds the xml document in.

obviously you'd need to import all relevant packages etc.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.xml.parsers.DocumentBuilder;
  3. import javax.xml.parsers.DocumentBuilderFactory;
  4. import javax.xml.parsers.FactoryConfigurationError;
  5. import javax.xml.parsers.ParserConfigurationException;
  6.  
  7. import org.xml.sax.SAXException;
  8. import org.xml.sax.SAXParseException;
  9.  
  10. import java.io.File;
  11. import java.io.IOException;
  12.  
  13. import org.w3c.dom.*;
  14.  
  15.  
2. The second way in java is to use the SAXP API, which doesn't load the XML file into memory. This is quicker than JAXP, and is useful when you know the structure of the xml file isn't going to change etc.

http://java.sun.com/j2se/1.5.0/docs/...SAXParser.html

Finally, to send it to mySQL, you need to open a connection String to the mySQL database, and then run whatever queries you want. You can use a system ODBC driver, or Sun's own JDBC driver if you haven't got the first one.

This isn't comprehensive, but should give you enough to start.....

mharrison
Dec 19 '06 #3
If you are familiar with SQL then you could try using Stels-XML JDBC driver and hibernate together.
I have used the combination successfully on a project.
Stels-XML is a commercial product but it allows you to read an XML file using SQL commands.
Hibernate takes Java objects and writes them to the database by generating the SQL for you.

Links:
Stels Stels-XML
Hibernate hibernate

As with the other solutions you'll also need a JDBC driver.
JDBC driver for MySQL

Best of luck.
Jan 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Eric Linders | last post by:
Hi, Pretty new to PHP/MySQL, but I have some programming experience in a past life. Hopefully you can help me out as I learn PHP/MySQL! :-) I have a MySQL database that includes customer...
7
by: AF | last post by:
I am a real novice to php and MySQL, with about a week's worth of reading and self tutoring. I have an urgent need to publish a database of information and need some guidance on how to do this. ...
0
by: JL | last post by:
Platform: Linux Red Hat RHEL 3 (and red hat 9) Installed MySQL from source. As a matter of fact, installed all LAMPS from source, and the mysql socket file was arranged in a place other than...
3
by: * Tong * | last post by:
or I have to be in some mlist in order to post? thanks -- Tong (remove underscore(s) to reply) *niX Power Tools Project: http://xpt.sourceforge.net/ - All free contribution & collection
2
by: Brett B | last post by:
I just installed mysql on linux. If I open a terminal, su to root, then type "mysql", I am able to connect to the server and run my queries. If I exit out of su so that I am my own id (baisley)...
4
by: NotGiven | last post by:
setting up LAMP server. on old server with single Intel PII 450 MGHz, 64 MG Ram and two 9.1 GB Hard drives. How much RAM do I need to run MySQL efficiently?
1
by: dimitri | last post by:
i try to copy data from excel into my MySql database which runs on a linux. i use MS Access to access the database. i need to optain the unique id number, and this is where i have some troubles....
1
by: ariel gons | last post by:
This is one of my project and also my thesis in school. How can I get data on database MYSQL using javascript function? Is there anybody here can help me with this problem.. Can anyone give...
1
by: Niraj175 | last post by:
How we can insert a value in database using database MySql for datatype LongText?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.