• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

JDBC CONNECTION

Is it possible to establish a database connectivity through JDBC once in the beginning of application and than executing SQL queries through out the application even in called classes

Regards

Milind
0
MILIND_JOG
Asked:
MILIND_JOG
1 Solution
 
agsaptCommented:
Of course you can. Use persistent connection to your database and you will be all right.


-=@gS=-
0
 
MILIND_JOGAuthor Commented:
Thanks for responce. It's 01:00 AM. I will come nack tomorrow.

Thanks

Milind
0
 
Sathish David Kumar NCommented:
ya you can ....

but if your close the window of the ur application then connection still remine , next it will creat a new connection only . so it will become huge problem  
0
 
Lo-TanCommented:
Why do you want to execute random SQL statements throughout your application?  Look at something like JPA for Java.  Create a simple layer for talking to your database model and put all the jpa behind that.  Then use that service wherever you need to run 'sql statements'.

Or open a JDBC connection and stuff it into a system property / Singleton class...   I don't really know what you're doing, but what you want to do doesn't sound practical/maintainable.
0
 
agsaptCommented:
The question would be how you structure your application to let this to happen? There are some techniques you can implement to allow such feature to exist in your application source code. And as stated by Lo-Tan, JPA for java is one of them.

But you can also write your own simple class that would implement an interface that contains commonly used functions related to database. E.g.

- createConnection
- createStatement,
- createParameters,
- executeQuery
- executeNonQuery
- etc .. etc ..

And make sure your class can be accessible from anywhere within your codes.

-=@gS=-
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now