开发者

Insert the xml file data into a database using java?

开发者 https://www.devze.com 2023-03-04 04:51 出处:网络
I wanted to insert data from a XML file to a d开发者_Go百科atabase with Java. This includes creating table, followed by inserting data in that from the XML file.I\'m not going to supply you with the c

I wanted to insert data from a XML file to a d开发者_Go百科atabase with Java. This includes creating table, followed by inserting data in that from the XML file.


I'm not going to supply you with the code to do it, but give you the direction:

There are two parts to your task:

  1. Parsing the xml - can be done by one of the many XML parsers to Java. refer to this question.

  2. Communicating with the database - can be done using JDBC, which has a nice tutorial here and another one here.


If this is a one time operation and/or you have LOTS of data, then you could consider bypassing the DB communication in Java (ala JDBC), and instead, you could stream the output to plain-text SQL script(s) containing valid (insert) SQL statements. Once you have the SQL script(s), then you could simply access your DB locally (via the command-prompt/line) and import your newly created SQL script(s).

To parse the XML, please refer to the URL provided by MByD in his point #1.


I'm not going to supply you with the code to do it, but give you the direction:

If this is a one time operation and/or you have LOTS of data, then you could consider bypassing the DB communication in Java (ala JDBC), and instead, you could stream the output to plain-text SQL script(s) containing valid (insert) SQL statements. Once you have the SQL script(s), then you could simply access your DB locally (via the command-prompt/line) and import your newly created SQL script(s).

To parse the XML, please refer to the URL provided by MByD in his point #1.

0

精彩评论

暂无评论...
验证码 换一张
取 消