Reading and writing Java to a local database?

I have a program that constantly receives information from the site and is constantly updated. At the moment, I save all this information in arraylist , and then when I finish, I write it to a text file.

I need to manipulate this information; however, it creates a massive text file, and I cannot read and write information to a text file constantly because it takes too much time. So someone told me to study database usage. The only database I have ever used was the MySQL database for the website, never with java.

Is there a way to make the database local? Like only on my computer (don't want to pay for web hosting when I'm the only one who accesses this information on my computer)? I was looking a bit for SQLite, but one of the things I saw is that it does not allow concurrency. I think about the multithreading of my program and at the same time reading and writing different sections. Is it possible?

Basically, I ask here:

  • Which database should I use?
  • How to install this database on my computer?
  • Some information on how to use Java jdbc? (read a little before)
  • Any textbooks on any of the above (video, text, etc.)
+4
source share
4 answers

It looks like your friend is right, and the database will significantly help you improve productivity.

  • You can really use any type of database. You can even continue to use MySQL by installing it locally and using Connector / J to connect in Java. Although embedded databases are probably the easiest. One of the options: Hypersonic DB (HSQLDB)
  • No need to "install" embedded databases. Just add their library (.jar file) to your project build path. When you "connect" to a database, you can usually tell the database how to use your file system to store your data.
  • JDBC stands for Java DataBase Connectivity. This is the API used by Java applications to communicate with databases. One of the important features of JDBC is that it (usually) doesn’t matter which database you are talking to, since the API for accessing any database is the same *.
  • Here is one tutorial for JDBC: Accessing the JDBC Database (TM)

* API for access to databases - for example. sending queries and getting results will usually be the same, but JDBC cannot hide differences in things like SQL. If you use ORM, such as Hibernate , this usually simplifies the handling of all small incompatibilities between the databases.

+7
source

You need a built-in Java database, for example. HSQL .

+1
source

There are various options for embedding an SQL database in your JVM, for example. Derby .

0
source

What you really need is a built-in Java database, you can find a huge list of them here: Comparison of built-in Java databases

0
source

All Articles