Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

5 replies to this topic
#1
Posted 15 January 2011 - 09:29 AM
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.
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.
#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.
All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.
#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".
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
My MineCraft server site: http://banishedwings.enjin.com/
#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

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
My MineCraft server site: http://banishedwings.enjin.com/
#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.
Also tagged with one or more of these keywords: connection
Language Forums →
Databases →
unable to read data from the transport connection an existing connection was forcibly closed by the remote host in postgresql...Started by viveq, 22 Aug 2013 ![]() |
|
![]() |
||
Language Forums →
PHP →
PHP Remote Server Database Connection ErrorStarted by KodeKool, 01 Mar 2013 ![]() |
|
![]() |
||
Language Forums →
Java →
NetBeans and Data Base connectionStarted by Petros, 16 Feb 2013 ![]() |
|
![]() |
||
Language Forums →
Other Languages →
ASP, ASP.NET and Coldfusion →
asp.net in my pc without internet connectionStarted by apysan, 28 Jan 2013 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Terminal and remote connectionsStarted by MaxBummer, 15 Jan 2013 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download