Solved

JDBC CONNECTION

Posted on 2010-11-30
5
263 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
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
create a gui in perl 3 67
Unable to start eclipse ? 17 127
Java Server Faces parameter pass? 6 37
VB Script to add site to Java Exception List 4 48
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now