File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes generalised code to connect to database engines using jdbc4? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "generalised code to connect to database engines using jdbc4?" Watch "generalised code to connect to database engines using jdbc4?" New topic
Author

generalised code to connect to database engines using jdbc4?

Pinak Bheed
Greenhorn

Joined: Feb 02, 2011
Posts: 2

hi,

i am developing an application which simulates datacubes and their operation. For this application i need to provide support for various database engines such as postgresql, mysql, etc.
i was planning on providing an interface where the user can choose the engine and specify its details.

i have been able to connect to postgresql using the jdbc4 driver available. for this connection i had to compile my program code by including the .jar driver in the classpath during compilation.
but the application as a product should run on JRE and there should be no need to recompile the code. is this possible?

the application should also be customizable to the newer versions of driver and engines available for the database. How can this be done? please guide me in the right direction

HOW CAN THIS CONDITIONALITY BE ACHIEVED?
please help.

thanks in advance


OCP, Java 6 Programmer
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19719
    
  20

See http://docs.oracle.com/javase/tutorial/jdbc/basics/index.html, especially http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html. In essence, you use Class.forName to load the driver class instead of hard coding it, and then use DriverManager to get the connection. There will only be two values you then may need to change - the class name and the connection string.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generalised code to connect to database engines using jdbc4?