Jdbc
Heeey guys!
it's the first time for me to post a thread here..
I have a big dilemma and I need your help..
I have a project at uni about making a JDBC ..here it is :
Introduction
JDBC (Java Database Connectivity) is a standard SQL database access interface, which provides
uniform access to a wide range of relational databases. It also provides a common base on which
higher-level tools and interfaces can be built. Basically, JDBC performs the following operations:
• Establish a connection with a database or access any tabular data source.
• Send SQL statements.
• Process the results.
JDBC defines a set of main interfaces to handle the previous three steps
java.sql.Driver
java.sql.Connection
java.sql.Statement
java.sql.Resultset
The Driver interface handle requests for database connections, the Connection interface provide
means for accessing the specified database and querying it using standard SQL queries.
Each SQL query need to be passed to the connection through an object implements Statement
interface, the return value of the query will be stored in an object implements ResultSet
interface.
The following code snippet for a simple JDBC program.
// Step 1 : Establish the conenction
// First, loading the driver
Class drvClass = Class.forName(“oracle.jdbc.driver.OracleDriver”);
DriverManager.registerDriver((Driver) drvClass.newInstance());
// Second, making the connection
Connection m_con = DriverManager.getConnection(m_url, m_userName, m_password);
// Step 2: Send SQL statement
Statement stmt = m_con.createStatement();
ResultSet rs = stmt.executeUpdate("SELECT e_name, e_salary FROM employee");
// Step 3: Process the result
while (rs.next())
{
String s = rs.getString("e_name");
float n = rs.getFloat("e_salary");
System.out.println("Name: " + s + "\t Salary: " + n);
} // Close connection and release resources
stmt.close();
m_con.close();
Problem Statement
It is required to implement and XML JDBC deriver that access and XML database and make
some queries on it.
First you will need to implement a simple Database Management System ,DBMS, that handles
XML tables, it is let for you to specifies the structure of your XML tables. You will use SAX
parser in parsing the tables data.
Second, you will implement the JDBC four main interfaces; java.sql.Driver, java.sql.Connection,
java.sql.Statement and java.sql.Resultset.
You won't implement all methods of the previous interfaces, instead you will use adapter classes
to handle the unneeded functions for our driver as the following.
java.sql.Driver
Will be implemented with all its methods.
java.sql.Connection
Implement the following methods; close(), commit(), createStatement(), isClosed(),
isReadOnly(), setReadOnly(boolean readOnly).
java.sql.Statement
Implement the following methods; addBatch(String sql), clearBatch(), close(),
executeBatch(), executeQuery(String sql), executeUpdate(String sql), getConnection(),
getMaxRows(), getQueryTimeout(), getResultSet(), getUpdateCount(), setMaxRows(int
max), setQueryTimeout().
java.sql.Resultset
Implement the following methods; absolute(int row), afterLast(), beforeFirst(),
cancelRowUpdates(), close(), deleteRow(), findColumn(String columnName), first(),
getObject(int columnIndex), getObject(String columnName), getRow(), getStatement(),
insertRow(), isAfterLast(), isBeforeFirst(), isFirst(), isLast(), last(), moveToCurrentRow(),
moveToInsertRow(), next(), previous(), relative(int rows) , rowDeleted(), rowInserted(),
rowUpdated(), updateObject(int columnIndex), updateObject(String columnName)
The resultant JDBC of your implementation should be able to run code like given in the
previous example and similar codes that execute SQL quires.
Our proposed XML driver will support the following SQL statements:
INSERT INTO table [ column [,column, …. ]]
VALUES (value [,value, … ))
UPDATE table
SET column=value [ , column=value, .. ]
[WHERE condition]
DELETE table
[WHERE condition]
SELECT { * | column [,column, …. ] }
FROM table
WHERE condition
Any syntax errors or invalid statements should be rejected.
In your implementation you must have a general class for logging your different error,
warnings and messages. It is recommended to use Log4J project for logging
-------------------------------------------------------
now I need an example of an implementation of any of the functions coz I don't know where to start!!!
please this is urgent
thanks a lot
Evronia
|