Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generalised code to connect to database engines using jdbc4?

 
Pinak Bheed
Greenhorn
Posts: 2
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic