Hi everyone I am new to this forum I need everyone's help to solve my problem, Here's the code I have to use this code at any other program or java class. As I am using this code frequently in all programs can anyone help how to call these code as a function or anything???
This is not the right way to use connections.
Use Connection pooling.
Using Connection you can easily write a reusable function which will solve your purpose.
Thanks everybody, actually what my master ask me to do is create a class and call them in your program but I am not getting that thing.
I shouldnot have that JDBC connection code in my every program but I have to use them by anymeans in my another java programs.
In program 1, add a method that returns a connection.
In program , create a DisplayDB object whenever you need connection object and call getConnection.
But most important thing about Connections are to close them as soon as you finish them so as to avoid holding up resources. So add method to close the connection object
Create a class called DB do the common connection coding in that class. Like driver manager, connection string etc. Then import this class in the required class to make a connection and do not forget to close all the opened connection.
I am not in a position to send you some sample code.But will post as soon as get hold of one
@Balu Sadhasivam
Thanks everyone for your help and forgive me for not answering for your solutions, I actually tried your code but I need somemore clear explanation and sample, But the thing is really superb, Thanks for everyones help.
Post by:autobot
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
a bit of art, as a gift, the permaculture playing cards