JDBC-ODBC Bridge driver for DBMaker

The "Write Once, Run Anywhere" Java Platform is a safe, flexible and complete cross-platform solution for developing robust Java applications for the Internet and corporate intranets. The open and extensible Java Platform APIs are a set of essential interfaces that enable developers to build their Java applications and applets.

JDBC

JDBC is short for Java DataBase Connectivity, and is a Java API that enables Java programs to execute SQL statements. The interface allows Java programs to interact with any SQL-compliant database. Since most relational database management systems (DBMSs) support SQL syntax, and Java can run on most platforms, JDBC provides the flexibility to write a database application that can run on different platforms and interact with different DBMSs.

JDBC is designed specially for Java programs. Sun Microsystems defined the JDBC standard that allows Java applications or Java Applets to access a database. Like ODBC, Java applications can access different databases through the same interface, but there is no need for client-side configuration, like a data source name. Therefore, JDBC is ideal for internet/intranet application design.

Another standard part of Java is the JDBC-to-ODBC bridge, which is a layer of code that implements the JDBC driver API by calls to the ODBC driver API. You can use this bridge and an ODBC driver, instead of a JDBC driver, to provide access to any database with an ODBC driver.

What is the JDBC-ODBC Bridge?

The JDBC-ODBC bridge provides JDBC API access via most ODBC drivers. Note that some ODBC binary code, and in many cases database client code, must be loaded on each client machine that uses this driver. This kind of driver is most appropriate on a corporate network, or for application server code written in the Java programming language in a 3-tier architecture.

How to install DBMaker JDBC-ODBC Bridge?

JDBC-ODBC Bridge is a driver for the client-end. In the server-end, you don't need to install any components or make special settings. DBMaker JDBC-ODBC Bridge includes two files for UNIX; libdmjdbc.so and dmjdbc.zip, and one file for Windows; dmjdbc.jar. You can find those files in the "driver/JDBC" directory after installing DBMaker.

The following steps teach you how to install and use the DBMaker JDBC driver in a UNIX environment.

Please note "/DBMAKER_HOME" stands for dbmaker's home directory.

1. Add "/DBMAKER_HOME/driver/JDBC" into your shell initialization file.

If you use sh or bash, please use the following command. For sh (.profile), bash (.bashrc), add

Shell> LD_LIBRARY_PATH=/DBMAKER_HOME/driver/JDBC:$LD_LIBRARY_PATH

Shell> export LD_LIBRARY_PATH

If you use csh or tcsh, please use the following command. For csh/tcsh (.cshrc), add

Shell> setenv LD_LIBRARY_PATH /DBMAKER_HOME/driver/JDBC

2. In order to find "dmjdbc.zip" while executing your java program, add the class path as below.

Shell> java -classpath

 ".:/lib/classes.zip:/DBMAKER_HOME/driver/JDBC/dmjdbc.zip"

your-java-program

          

The following step teaches you how to install and use the DBMaker JDBC driver in a Windows environment.

1. Add the class path when executing Java programs For example, if you use JDK 1.2

% java -classpath

 ".:/lib/tools.jar:/DBMAKER_HOME/driver/JDBC/dmjdbc.jar"

your-java-program

You can also set "classpath" in autoexec.bat.

How to connect DBMaker via JDBC-ODBC Bridge
Step 1: register JDBC-ODBC Bridge

In order to use the JDBC-ODBC Bridge, first of all, you need to use the Java Class Loader to register the class of JDBC-ODBC Bridge. The syntax is below:

Class.forName(dbmaker.sql.JdbcOdbcDriver)

Then, the Java Class Loader can find the assigned class according to CLASSPATH.

Step 2: Connect database

The syntax to connect to DBMaker is as below:

DriverManager.getConnection("jdbc:dbmaker:DSN", User, Password);

DSN is Data Source Name, User is login account, and Password is login password.

Using those two steps, you should be able to retrieve and update your database.

Samples
import java.io.*; /* Import IO classes */

 import java.sql.*; /* Import SQL classes */







public class my {                    /* define my class */

   private static final String dbUser = "SYSADM";

                              /* define a string variable */

   private static final String dbPwd = "";

                              /* define a string variable */

   private static final String dbSrc = "DBSAMPLE";

                              /* define a string variable */

  

   public static void main(String argv[]) { /* declare main program */



   System.out.println("register dbmaker driver \n"); /* print a string */

   try {

   String jdbcDriver = "dbmaker.sql.JdbcOdbcDriver";

                                     /* define a string variable */

   Class.forName(jdbcDriver).newInstance(); /* register jdbc-odbc bridge*/



   System.out.println("connect to database \n"); /* print a string */

   Connection conn = DriverManager.getConnection("jdbc:dbmaker:"+dbSrc,

   DbUser, dbPwd);                     /* connect database */



   System.out.println("get a statement object to create table

jdbc_employee\n");



   Statement stmt = conn.createStatement(); /* create a statement */

   Stmt.executeUpdate("create table jdbc_employee (id int, name char(20),

 salay float, hired_date date)");



   System.out.println("insert constant data into table jdbc_employee\n");

   Stmt.executeUpdate("insert into jdbc_employee values (1,'Charles

 Brown', 555.32, '1999/01/01')");



   System.out.println("commit work \n");

   Conn.commit();

   System.out.println("drop table jdbc_employee \n");

   Stmt.executeUpdate("drop table jdbc_employee");



   System.out.println("close statements \n");

   Stmt.close();



   System.out.println("close connection \n");

   Conn.close();

   } catch( Exception ex )

      {

       System.out.println(ex.getMessage());

      Ex.printStackTrace();

      }

     } /* end of main() */

    } /* end of class */