Java读写本地数据库? [英] Java reading and writing to a local database?

查看:600
本文介绍了Java读写本地数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,它不断从网站获取信息并不断更新。截至目前,我将所有信息存储在 arraylist 中,然后当我完成后,我将其写入文本文件。

I have a program which is constantly getting information from a website and is constantly updating. As of now I store all that information in an arraylist and then when I am done I write it to a text file.

我需要操纵这些信息;然而,它创建了一个庞大的文本文件,我无法不断地读取和写入文本文件,因为它需要太长时间。所以有人告诉我要研究使用数据库。我曾经使用过的唯一一个数据库是网站的MySQL数据库,而不是java。

I need to manipulate that information; however, it creates a massive text file and I can't constantly read and write information to a text file because it takes too long. So someone told me to look into using a database. The only database I have ever used was a MySQL database for a website, never with java.

有没有办法让数据库本地化?就像在我的电脑上一样(当我是唯一一个在我的电脑上访问这些信息的人时,不想支付网络托管费用)?我看了一点SQLite,但我看到的一件事是它不允许并发。我正在考虑对我的程序进行多线程处理,并让它同时读写不同的部分。这可能吗?

Is there any way to make a database local? As in only on my computer (don't want to pay for web hosting when I am the only one accessing this information at my computer)? I was looking a little bit into SQLite but one of the things I saw was that it does not allow concurrency. I'm thinking of multi-threading my program and having it read and write different sections at the same time. Is this possible?

基本上我在这里要求的是:

Basically what I'm asking for here is:


  1. 什么类型的我应该使用数据库吗?

  2. 如何在我的计算机上安装该数据库?

  3. 有关如何使用Java jdbc的一些信息?(正在阅读

  4. 任何上述任何教程(视频,文字等)

  1. What type of database should I use?
  2. How do I install that database on my computer?
  3. Some information on how to use Java jdbc?(was reading a little into it before)
  4. Any tutorials on any of the above (video, text, etc)


推荐答案

听起来你的朋友是正确的,数据库可以极大地帮助你提高性能。

It sounds like your friend is correct and a database would greatly help you improve performance.


  1. 你真的可以使用任何类型的数据库。您甚至可以通过在本地安装MySQL并使用 Connector / J 继续使用MySQL用Java连接。虽然可嵌入数据库可能是最简单的。一个选项是 Hypersonic DB(HSQLDB)

  2. 无需安装 可嵌入数据库。只需将他们的库(.jar文件)添加到项目的构建路径中。当您连接到数据库时,通常可以告诉数据库使用文件系统上的某个位置来存储其数据。

  3. JDBC代表Java数据库连接。它是Java应用程序用于与数据库通信的API。 JDBC的一个重要特性是它(通常)与您正在谈论的数据库无关,因为用于访问任何数据库的API是相同的*。

  4. 这是一个教程JDBC: JDBC(TM)数据库访问

  1. You can really use any type of database. You can even continue using MySQL by installing it locally and using Connector/J to connect in Java. Though embeddable databases are probably the easiest. One option is Hypersonic DB (HSQLDB)
  2. There is no need to "install" embeddable databases. Simply add their library (.jar file) to your project's build path. When you "connect" to the database, you can usually tell the database to use a location on your filesystem to store its data.
  3. JDBC stands for Java DataBase Connectivity. It is the API used by Java applications to communicate with databases. One of the important features of JDBC is that it (usually) does not matter which database you are talking to as the API for accessing any database is the same*.
  4. Here is one tutorial for JDBC: JDBC(TM) Database Access

*用于访问数据库的API - 例如发送查询和检索结果 - 通常是相同的,但JDBC无法隐藏SQL之类的差异。如果您使用像 Hibernate 这样的ORM,通常可以更轻松地处理数据库之间的所有小的不兼容性。

*The API for accessing databases--e.g. sending queries and retrieving results--will generally be the same but JDBC can't hide differences in things like SQL. If you use an ORM like Hibernate, it can usually make it much easier to handle all the little incompatibilities between databases.

这篇关于Java读写本地数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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