0

I'm developing a Java Desktop Application using JDBC, and I wanted to manage the concurrent access to the Database. Someone told me to use Sessions but after some research it turned out that Sessions are not possible in Desktop app.

This is why I'm asking for some help. You have any ideas on how to manage this thing.

Thanks

4
  • 2
    I'm assuming you have several background/worker threads using database connections. Could you clarify what the issue would be? Is it about defining transactions in your desktop app? Commented Jul 4, 2011 at 15:44
  • Yes, the app will be accessed by many many users who will do some (INSERT, UPDATE, ...) This is why I'm thinking to manage this mess. Commented Jul 4, 2011 at 15:45
  • 1
    The same desktop app will be accessed by many users at the same time, or each of them will have their own instance? Commented Jul 4, 2011 at 15:47
  • each user will have his own instance, but the transactions will be executed in the Database Engine. Commented Jul 4, 2011 at 15:49

3 Answers 3

4

From what you described, I recommend you to check for SQL exceptions while trying to insert or update some row that may be already be changed by someone else. In that case maybe you should reload what your app shows to the user so they have up-to-date data. Another option is to show a user-friendly error.

If your app executes several queries (insert, update) in a row, I suggest using transactions. I think the easiest way to set them in a Desktop app is to use the Spring framework, if you are familiar with it.

Sign up to request clarification or add additional context in comments.

Comments

2

It is not clear exactly what you mean by manage concurrent access - do you want to avoid multiple select queries to the DB? In that case using SELECT for UPDATE might be an option. If you are looking for more general method in limiting only single user to access the DB at any time, you will have to roll your own locking mechanism in the code I suppose.

Comments

1

So long as each Thread is using a different Connection, there should not be any concurrency issues in the JDBC. There are any number of ways to achieve this. e.g. ThreadLocal or a connection pool.

I don't see how a single desktop app can be accessed by many users. You can have many copies of a desktop app and each user has their own connections. This shouldn't cause an issue. You need to clarify what your concern is.

2 Comments

each user will have his own instance, but the transactions will be executed in the Database Engine.
@dotNET, that's what transactions do for you when you used the correctly. There is nothing to be done in Java.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.