Posted by aschunkjava
on September 28, 2007 at 12:04 PM PDT
Are you frequently working with JDBC or going to learn JDBC? I have written a simple JDBC API for just that purpose. db4j is a simple OOP driven Wrapper around JDBC.
db4j: A simple Database API
If you are working a lot with Java DB then you repeatedly perform a few tasks every time and some only once.
For instance establishing a connection with a database and open a table of database usually happens at least once until you are working with more than one database. With JDBC you need to do the following for establishing the connection:
conn = DriverManager.getConnection(dbname, username, password);
System.out.println("Error! Unable to connect to " + dbname);
System.out.println("Cause: " + e.getSQLState());
Given a Connection object called conn the code above is used for setting up a connection with a database with your username and password.
With db4j you can connect to a database as follows:
DBConnection db = new DBConnection();
String dbname = "BeispielDB.txt";
String usrname = "admin";
String password = "adminadmin";
String constring = "sun.jdbc.odbc.JdbcOdbcDriver";
db.connect(conn,constring, "admin", "adminadmin");
db.open(conn, constring, usrname, password);
This simplifies the connection process to creating an object of class DBConnection and calling its open() method with a few parameters.
The DBConnection class offers basic methods for connecting to a database, open a database and close the connection.
To reduce programming with JDBC or derby db4j offers a set of classes that consists of the following classes:
The name of these classes are almost self describing. The DBActions class provides database transactions such as Auto-Commit, Rollback etc.
Note that your DBMS might not support all these featurs so have to consult your DBMS documentation.
DBLogger is a simple Logger class that uses JDBC Logger methods. The DBDriverInfo provides information about the database driver.
In a future release i will add a statement class and some utility methods for retrieving and setting database values.