Database connection layer in java

Posted on 2004-11-25
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

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

    Author Comment

    A standalone Java application.
    LVL 35

    Accepted Solution

    1) You need to either use type 3 or type 4 (pure Java) drivers. Have a look here for more info:

    2) Some of them are. Have a look here:

    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:
    LVL 13

    Assisted Solution

    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

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

    LVL 3

    Expert Comment

    Why to reinvent the wheel?
    Use Hibernate instead:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    779 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

    18 Experts available now in Live!

    Get 1:1 Help Now