1

I have been creating a large application to be used in my workplace and it needs to be expanded upon.

I have begun migrating my data to SQLite databases which works very well in handling multiple, concurrent SELECT requests.

However, we now have multiple users that need to be able to write data back to the database at any given moment. The databases currently reside on a shared network drive.

There are two problems with this scenario:

  1. Only one write operation may be performed at a time. If more than one user is attempting to write at the same time, one of them will fail and Java throws an SQLException.
  2. I do not have access to install a database server. I am fairly new to databases but I understand a database server is one way to allow concurrent write access to databases. However, in my work environment, I do not have the ability to install or administer such software.

Are there any other options for this scenario? Would there be a way for Java itself to handle the issue with the databases being locked?

I was thinking of just opening a new thread and continually trying to write to the database until it's successful, but such a brute-force tactic seems really irresponsible and unnecessary.

Zephyr
  • 9,885
  • 4
  • 28
  • 63
  • Are the writes to the db time consuming? If a write fails, could you wait a second and then try again? – SedJ601 Jun 20 '17 at 19:17
  • The writes are currently very quick. I had considered using a slight pause/retry but was worried I would still run into problems in the future if the data and user-base continues to grow. I will try that for now, but would still love to hear if there are other, more permanent solutions. – Zephyr Jun 20 '17 at 19:20
  • The duplicate link seems to be informative. – SedJ601 Jun 20 '17 at 19:21
  • That looks promising, Sedrick. Thank you for adding that. Where does the code in answer 2 go, though? Is that a separate statement I send to SQLite before the write request? – Zephyr Jun 20 '17 at 19:35
  • I didn't add it. @CL added it. I am not sure how it works. I have never used it. – SedJ601 Jun 20 '17 at 19:39
  • 1
    The busy timeout settings applies to the connection, so you would execute it after opening the connection. – CL. Jun 20 '17 at 20:50

0 Answers0