?
Solved

JDBC CONNECTION

Posted on 2010-11-30
5
Medium Priority
?
273 Views
Last Modified: 2012-05-10
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
Comment
Question by:MILIND_JOG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:agsapt
ID: 34240797
Of course you can. Use persistent connection to your database and you will be all right.


-=@gS=-
0
 

Author Comment

by:MILIND_JOG
ID: 34241733
Thanks for responce. It's 01:00 AM. I will come nack tomorrow.

Thanks

Milind
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34241889
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
 
LVL 4

Expert Comment

by:Lo-Tan
ID: 34243350
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
 
LVL 5

Accepted Solution

by:
agsapt earned 2000 total points
ID: 34245503
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question