Monday, March 3, 2008

Generalize Base Dao provide Data Access Object

Common Dao which useful to access DataBase..Provide Database connection to all classes.
You can found other Driver Information At :

http://www.dbschema.com/drivers.html


* Cache
* DaffodilDB
* DB2 for Windows/Linux
* Firebird
* FrontBase
* Informix
* JavaDB/Derby

* Microsoft_SQL_Server
* Microsoft_SQL_Server_2005
* Microsoft_Access
* TDS JDBC Driver
* Mimer
* MySQL

* Oracle
* Pervasive
* PointBase
* PostgreSQL
* Sqlite
* Sybase_SQL_Anywhere
* Sybase_ASE

MySQL


* Required File(s): mysql-connector-java-nn-bin.jar
* Java Driver Class: com.mysql.jdbc.Driver
* URL Pattern: jdbc:mysql://<host>:<port3306>/<db>
* Website: MySQL

Oracle

* Required File(s): ojdbc15.jar (For Java 1.5), ojdbc16.jar (For Java 1.6)
* Java Driver Class: oracle.jdbc.OracleDriver
* URL Pattern: jdbc:oracle:thin://<host>:<port>/<service> jdbc:oracle:thin:<host>:<port>:<SID> jdbc:oracle:thin:<TNSName> (from 10.2.0.1.0)
* Website: Oracle

PostgreSQL

* Required File(s): postgresql-nn.jdbc3.jar
* Java Driver Class: org.postgresql.Driver
* URL Pattern: jdbc:postgresql://<host>:<port5432>/<db>
* Website: PostgreSQL

HSQLDB
HSQLDB may run in two modes: local and server mode. In the local mode the database engine is started directly by the driver, and the software will run in the same thread, locally.

* Required File(s): hsqldb.jar
* Java Driver Class: org.hsqldb.jdbcDriver
* URL Pattern: jdbc:hsqldb:<db> or jdbc:hsqldb:hsql://<host>:<port> for the server mode
* Website: HSQLDB

JavaDB/Derby

* Required File(s): derbyclient.jar
* Java Driver Class: org.apache.derby.jdbc.ClientDriver
* URL Pattern: jdbc:derby:net://<host>:<port1527>/<db>
* Website: Apache Software Foundation

Mimer

* Required File(s): mimjdbc3.jar
* Java Driver Class: com.mimer.jdbc.Driver
* URL Pattern: jdbc:mimer://<host>:<port>/<db>
* Website: Mimer Information Technology

Pervasive

* Required File(s): pvjdbc2.jar
* Java Driver Class: com.pervasive.jdbc.v2.Driver
* URL Pattern: jdbc:pervasive://<host>:<port>/<db>
* Website: Pervasive

Informix

* Required File(s): ifxjdbc.jar
* Java Driver Class: com.informix.jdbc.IfxDriver
* URL Pattern: jdbc:informix-sqli://<host>:<port>/<db>:informixserver=<dbservername>
* Website: IBM

Microsoft SQL Server

* Required File(s): sqlserver.jar
* Java Driver Class: com.microsoft.jdbc.sqlserver.SQLServerDriver
* URL Pattern: jdbc:microsoft:sqlserver://<host>:<port1433>;DatabaseName=<db>
* Website: Microsoft

jTDS JDBC Driver
Download the jtds-nn-dist.zip file, unzip it and then load the jtds.jar file

* Required File(s): jtds-1.2.2.jar
* Java Driver Class: net.sourceforge.jtds.jdbc.Driver
* URL Pattern: jdbc:jtds:sqlserver://<host>[:<port>][/<db>]
* Website: jTDS web site

Microsoft SQL Server 2005

* Required File(s): sqljdbc.jar
* Java Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver
* URL Pattern: jdbc:sqlserver://<host>[:<port1433>];databaseName=<db>
* Website: Microsoft

jTDS JDBC Driver
Download the jtds-nn-dist.zip file, unzip it and then load the jtds.jar file

* Required File(s): jtds-1.2.2.jar
* Java Driver Class: net.sourceforge.jtds.jdbc.Driver
* URL Pattern: jdbc:jtds:sqlserver://<host>[:<port>][/<db>]
* Website: jTDS web site

Microsoft Access
The standard jdbc-odbc driver does not implement the required methods, so you can only try one of the commercial drivers like Easysoft one. It is also possible to install one of the SQLServers and import the Access database in. Than follow the SQLServer instructions to import the schema in DbSchema.
Cache

* Required File(s): CacheDB.jar
* Java Driver Class: com.intersys.jdbc.CacheDriver
* URL Pattern: jdbc:Cache://<host>:<port>/<namespace>
* Website: Cache

DaffodilDB
DaffodilDb may run in two modes: local and server mode. In the local mode the database engine is started directly by the driver, and the software will run in the same thread, locally.
Local version

* Required File(s): DaffodilDB_Embedded.jar, DaffodilDB_Common.jar
* Java Driver Class: in.co.daffodil.db.jdbc.DaffodilDBDriver
* URL Pattern: jdbc:daffodilDB_embedded:<db>
* Website: DaffodilDB

Server version

* Required File(s): DaffodilDB_client.jar
* Java Driver Class: in.co.daffodil.db.rmi.RmiDaffodilDBDriver
* URL Pattern: jdbc:daffodilDB://<host>:<port3456>/<db>
* Website: DaffodilDB

DB2 for Windows/Linux

* Required File(s): db2jcc.jar, db2jcc4.jar, db2jcc_license_cu.jar (optional)
* Java Driver Class: com.ibm.db2.jcc.DB2Driver
* URL Pattern: jdbc:db2://<host>:<port50000>/<db>
* Website: IBM

FrontBase

* Required File(s): frontbasejdbc.jar
* Java Driver Class: com.frontbase.jdbc.FBJDriver
* URL Pattern: jdbc:FrontBase://<host>:<port>/<db>
* Website: FrontBase


PointBase
HSQLDB may run in two modes: local and server mode. In the local mode the database engine is started directly by the driver, and the software will run in the same thread, locally.
Local version

* Required File(s): pbembedded.jar
* Java Driver Class: com.pointbase.jdbc.jdbcUniversalDriver
* URL Pattern: jdbc:pointbase:embedded:PBPUBLIC
* Website: PointBase

Server version

* Required File(s): pbclient.jar
* Java Driver Class: com.pointbase.jdbc.jdbcUniversalDriver
* URL Pattern: jdbc:pointbase:server://<host>:<port>/<db>
* Website: PointBase

Sqlite
Download the driver from here. The driver does not implement all the interface methods. Therefore the reverse engineering of Foreign Keys does not work.

* Required File(s): sqlitejdbc-v056.jar
* Java Driver Class: org.sqlite.JDBC
* URL Pattern: jdbc:sqlite:<DB>
* Website: Sqlite

Sybase SQL Anywhere
The driver is usually delivered as zip file. First you need to unzip this file and locate then jconn3.jar file which usually is stored in the classes directory.

* Required File(s): jconn3.jar
* Java Driver Class: com.sybase.jdbc3.jdbc.SybDriver
* URL Pattern: jdbc:sybase:Tds:<host>:<port>?ServiceName=<db>
* Website: Sybase

Sybase ASE

* Required File(s): jtds-1.2.2.jar
* Java Driver Class: net.sourceforge.jtds.jdbc.Driver
* URL Pattern: jdbc:jtds:sybase://<host>[:<port>][/<db>]
* Website: JTDS

Sybase ASE

* Required File(s): jaybird-full-xxx.jar
* Java Driver Class: org.firebirdsql.jdbc.FBDriver
* URL Pattern: jdbc:firebirdsql://<HOST>:<PORT:3050>/<FILE>
* Website: Firebird


Code is Below
/*
* BaseDao.java
*/


package com.joshi.db.core;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Shirin Joshi
 * 
 */

public class BaseDao {
 private static final String CLASSNAME = BaseDao.class.getName();

 // Standard internal error messages
 public static String CONNECTION_URL = "";

 public static String CONNECTION_CLASS_NAME = "";
 static {
  CONNECTION_URL = "jdbc:sqlserver://127.0.0.1\\SQLEXPRESS;"
    + "databaseName=MyDB;user=sa;password=sa;";
  CONNECTION_CLASS_NAME = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
 }

 public static Connection getDbConnection() {
  Connection connection = null;
  try {
   try {
    Class.forName(CONNECTION_CLASS_NAME);
   } catch (ClassNotFoundException e) {
    System.out.println("Exception in Classloading :: ");
    e.printStackTrace();
   }
   connection = DriverManager.getConnection(CONNECTION_URL);
  } catch (SQLException e) {
   System.out.println("Error getting connection. Data Source = "
     + e.toString());
  }
  return connection;
 }

 public static void closeDbConnection(Connection p_connection) {
  if (p_connection != null) {
   try {
    p_connection.clearWarnings();
    p_connection.close();
   } catch (Exception e) {
    System.out.println("Error closeDbConnection = " + e.toString());
   }
  }
 }

 public static void closeStatement(Statement p_stmnt) {
  if (p_stmnt != null) {
   try {
    p_stmnt.close();
   } catch (Exception e) {
    System.out.println("Error closeStatement. " + e.toString());
   }
  }
 }

 public static void closeResultSet(ResultSet p_rs) {
  if (p_rs != null) {
   try {
    p_rs.close();
   } catch (Exception e) {
    System.out.println("Error closeResultSet. " + e.toString());
   }
  }
 }

}

No comments:

Contributors