How to import data to an in-memory database?

喜夏-厌秋 提交于 2019-12-08 03:36:48

问题


Are there any ways to import data in databases such as MS SQL, MySQL into in-memory databases like HSQLDB, H2 etc ?


回答1:


H2 supports a special database URL that initialized the database from a SQL script file:

"jdbc:h2:mem;INIT=RUNSCRIPT FROM '~/create.sql'"

HSQLDB and Apache Derby don't support such a feature as far as I know.




回答2:


I think you need to do

  1. query the data out from MS SQL

  2. import the data into in-memory DB with its API

Either SQL expressions or DB related APIs




回答3:


In Hibernate: Adding import.sql to the class path works great, hbm2dll checks if the file exists and executes it. The only details is that every sql command most be on one row, otherwise it will fail to execute




回答4:


You could dump the data as SQL INSERT statements then read it back.

You could read to a temporay object (like a struct) then write back to the internal db.




回答5:


Look at the free "universal database converter" http://eva-3-universal-database-converter-udc.optadat-com.qarchive.org/ -- it does claim to support MySQL, MS-SQL, and HSQLDB, among others.




回答6:


It really depends on what ways you think about. Is there a tool that could do it automatically without programming? Maybe.

Do you want to develop it? Then find out whether your favorite language supports both database engines(standard and in memory) and if it does, just write a script that does it. Process everything in chunks(fetch n rows at a time then insert them; repeat). How big the chunk size? It's up to you, try different sizes(say 100, 500, 1k etc.) see which one performs better on your hardware, fine tune to the sweet spot.

If your favorite language on the other hand doesn't support both of them, try using something that does.




回答7:


You can use dbunit for dumping the database to xml files and importing it back to another rdbms.




回答8:


Latest versions of HSQLDB allow you to open a CSV (comma separated values) or other delimiter separated data file as a TEXT TABLE in HSQLDB even with mem: databases, which can then be copied to other tables.

As others have pointed out, there are also capable and well maintained third party tools for this purpose.



来源:https://stackoverflow.com/questions/903832/how-to-import-data-to-an-in-memory-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!