[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Database connection layer in java

Posted on 2004-11-25
Medium Priority
Last Modified: 2010-03-31
Hi All

I need to write a database connection layer using java and jdbc. It should be able to connect to various databases including oracle, db2, sql server.

I have been able to write a small class using jdbc-odbc bridge drivers. But these drivers requires end user to create a DSN on their machine.

1. I need to know which drivers should I use  so that end users do not need to create DSN. they will just provide necessary DB information to my class and class will take care of everything.
2. Are these free drivers?
3. I have never written a complete DB layer. What are the essential methods this should have?

Depending on the answers I'll post further queries.

Question by:avi_india
LVL 86

Expert Comment

ID: 12674251
What is the context - a web application? You can, btw, create a DSN-less connection

Author Comment

ID: 12674275
A standalone Java application.
LVL 35

Accepted Solution

girionis earned 700 total points
ID: 12674277
1) You need to either use type 3 or type 4 (pure Java) drivers. Have a look here for more info: http://www.javaworld.com/javaworld/jw-07-2000/jw-0707-jdbc.html

2) Some of them are. Have a look here: http://servlet.java.sun.com/products/jdbc/drivers

3) It should basically be independent of other layers. For example if you change somethign in the upper/lower layer the database layer should not be affected. There are no specific methods you should include but in a few words you should have a method that loads the appropriate driver (maybe through a config file), and opens and closes connections to the database. Mayeb you should get more advance and look at concepts such as connection pooling and stuff but this is depends on the design of your implementation. If you need info on that though you can have a look here: http://www.webdevelopersjournal.com/columns/connection_pool.html
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 13

Assisted Solution

petmagdy earned 700 total points
ID: 12674282
if ur application will run over application servers u will need not to develop connection layers at all u will use Datasource methods to get and release database connection, also the datasource configuration will hide the JDBC drivers details from the development

>>1. I need to know which drivers should I use  so that end users do not need to create DSN. they will just provide necessary DB information to my class and class will take care of everything.
use each DB vender JBDC driver for example user Oracle thin/OCI drivers to use Oracle DB, etc
>> 2. Are these free drivers?
all Vendors drivers are free as long as u have the database licence

Author Comment

ID: 12674296
Gotta go now. Will look at these tomorrow and try them. Hopefully they will help me in addressing this problem.


Expert Comment

ID: 12679592
Why to reinvent the wheel?
Use Hibernate instead: http://www.hibernate.org/

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 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