如何使用Java从PostgreSQL数据库中的现有数据库中创建新的XML文件 [英] how can I create new XML file from existing database in PostgreSQL database using java

查看:98
本文介绍了如何使用Java从PostgreSQL数据库中的现有数据库中创建新的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将XML数据(从网页中获取)插入PostgreSQL数据库的最佳方法是什么?
我正在使用Java,需要一些帮助,以找到一种将这些数据读入数据库的好方法.

What would be the best way to insert XML data (that I get from a webpage) into PostgreSQL database?
I'm using Java and need a little help finding a good way to read this data into the database.

推荐答案

Postgres有(感谢Daniel Lyons指出)此演示文稿应该为您提供一些想法,不同的可能性是什么

Postgres has (thanks to Daniel Lyons for pointing it out) native XML support which you can use to store your table. If you however want to shred your XML data manually, there are different possibilities to represent XML data in a database. The first question should be, if you want a very generic solution, that will be able to store any XML document or one that is specific to your domain (i.e. only allows XML documents of a certain structure). Depending on that, you will have a very flexible, universal representation which is however harder to query (the SQL needed will be quite complicated). If you have a more specific approach, the queries will be simpler, but you will need to create new tables or add new attributes to existing talbes every time you want to store another type of document or add a field to an existing document; so changing the schema will be harder (which is one major advantage of XML). This presentation should give you some ideas what are the different possibilities.

此外,您可能会考虑切换到一些支持Xquery的数据库,例如 DB2 .使用针对处理XML的语言XQuery进行本地查询的能力将大大简化工作.

Also, you might consider to switch to some DB that supports Xquery, like DB2. The ability to natively query using XQuery, a language targeted at processing XML, will simplify things a lot.

更新:给出您的评论,您的XML数据(即您链接到的 )是完全相关的.可以将1:1映射到下表:

UPDATE: Given your comment, your XML data (that you linked to) is perfectly relational. It can be mapped 1:1 to the following table:

CREATE TABLE mynt (
    ID          SERIAL     ,
    myntnafn    CHAR(3)    ,
    myntheiti   Varchar(255) ,
    kaupgengi   Decimal(15,2) ,
    midgengi    Decimal(15,2) ,
    solugengi   Decimal(15,2) ,
    dagsetning  TimeStamp      
)

因此,任何mynt标记都将是表中的记录,而相应的子标记则是属性.我从您的数据中收集的数据类型可能是错误的.主要问题是IMO,因为没有自然主键,所以我添加了一个自动生成的主键.

So any mynt tag would be a record in the table and the corresponding sub-tags the attributes. The data types I gathered from your data, they might be wrong. The main problem is, IMO, that there is no natural primary key, so I added an autogenerated one.

这篇关于如何使用Java从PostgreSQL数据库中的现有数据库中创建新的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆