I'm currently developing my first Java desktop application using MSSQL as a back end. I've initially designed the app to have a database object which would allow me to pass my sql statements to the object and then have the object send the resultset back. However, it seems that the calling object has to carry the overhead of the try/catch code just to call the database object.
So, my question is, should I just be opening and using my database only when needed and code for each occurrence where it is needed? Or am I heading down the right path of opening my database at the start of app load and pass sql/resultsets to my database object?
Thx.
5 replies to this topic
#1
Posted 15 January 2011 - 09:29 AM
|
|
|
#2
Posted 15 January 2011 - 05:56 PM
Certain databases have limited number of maximum connections, in a web environment a persistent connection is very limiting. In your case of a desktop application, and MSSQL being slow at connections as needed a persistant connection can be advantageous if you are using it in a constant manner.
If you are just utilizing a database on-load and on-save (occasionally) then you can consider if you would be advantageous or not.
If you are just utilizing a database on-load and on-save (occasionally) then you can consider if you would be advantageous or not.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 16 January 2011 - 06:19 AM
I do almost all of my database work in Delphi, not Java. With that said, for database heavy applications it's usually worthwhile to have a single, persistent database connection object, and queries that use it as needed. Error trapping is generally done in the code that has the query, since that is where you can actually interpret the significance and nature of the error, and react accordingly.
SQL queries can throw a lot of errors that range from "you completely hosed up this statement, programmer", to "yeah, it should have worked, but somebody else beat you to this primary key".
SQL queries can throw a lot of errors that range from "you completely hosed up this statement, programmer", to "yeah, it should have worked, but somebody else beat you to this primary key".
#4
Posted 18 January 2011 - 03:11 PM
Delphi is pretty cool. I'm an old Turbo Pascal hack from way back. However, I'm doing this to make myself more marketable. Looks like I'll go with the persistent connection. Plus, I like being able to write all my error traps in one spot.
Thanks for the feedback.
Thanks for the feedback.
#5
Posted 18 January 2011 - 04:39 PM
I usually put my error traps around where I'm handling individual queries (either making the query or processing the record set). It's easier to control detailed error messages that way :)
#6
Posted 19 January 2011 - 03:03 AM
Due to the large resource cost associated with database connections I would use the singleton pattern, especially if you only need a single connection to a single database. This should minimize resource usage and allow for easy use.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









