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
MILIND_JOGAsked:
Who is Participating?
 
agsaptConnect With a Mentor Commented:
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
 
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 NArchitectCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.