0

i have some simple data xml to need insert them into database, if possible we can insert the data xml to database. i use common database like xml. i do searching doing many way, like i planning to convert xml data into string xml first but after that i was confuse how insert string xml to database.

<?xml version="1.0"?>
<books>
  <book id="1">
    <title>Java Complete Reference</title>
    <genre>Computer</genre>
    <price>700</price>
    <publish_date>2000-10-01</publish_date>
  </book>
  <book id="2">
    <title>Java Cookbook</title>
    <genre>Computer</genre>
    <price>950</price>
    <publish_date>2000-12-16</publish_date>
  </book>
</books>

the plan i need data xml when we input in jtextarea is can insert into database. how i need to do.

Tos Mario
  • 13
  • 5
  • The database structure is not defined. Can you elaborate please? – MJG Dec 05 '22 at 08:59
  • database i use MYSQL, i was planning insert the sample data xml i input up there into mysql. i was searching internet how do that. the first plan i was try was convert the data xml up there into string, but after that i was get trouble how insert that string data into database. – Tos Mario Dec 05 '22 at 09:07
  • So you want to insert a row in MySQL for each book in your input, with the columns title, genre, price and publish_date? But you don't know how to extract the single values from XML, or how to insert the data using SQL? – MJG Dec 05 '22 at 09:14
  • the plan i need insert all XML data and insert that xml to sql, like you say in a row – Tos Mario Dec 05 '22 at 09:18
  • To read the values to insert for each row, maybe use XPath, like described here: https://stackoverflow.com/questions/2811001/how-to-read-xml-using-xpath-in-java And then you could insert the data into the database as row-data. – MJG Dec 05 '22 at 09:26
  • is it possible to insert all xml data (tag and input) into database? – Tos Mario Dec 06 '22 at 04:18
  • This is possible. I suppose it should be a field of BLOB type. The limitation in this case you couldn't select data by the information inside, such as publish-data. Therefore a common approach would be to extract the values and insert each to a different field, according to relational database concepts. Further, you'd also consider resolving the genre from a separate entity for better normalisation. – MJG Dec 06 '22 at 12:27

0 Answers0