2 messages in com.mysql.lists.javaRe: Importing Connection & Framework
FromSent OnAttachments
Albert11 Nov 2000 01:26 
Stephan Gruschke11 Nov 2000 04:54 
Subject:Re: Importing Connection & Framework
From:Stephan Gruschke (lur@commedia-group.de)
Date:11/11/2000 04:54:32 AM
List:com.mysql.lists.java

Hi ho di Do,

A> Hi all, I am writing java code for connectiong to a MySQL database and A> working with its data. I use Mark Matthews' driver, but in the code I A> imported java.sql.Connection; everything works out fine, but is it an A> error? Is it better to import org.gjt.mm.mysql.Connection? A> Of course, I think this question can be extended to Statement, A> PreparedStatement and ResultSet. You should only import org.gjt.mm.mysql.Connection, if u need functionality which is not implemented in java.sql.Connection. As far as my personal knowledge goes, there's currently no additional functionality implemented in the mySQL-Driver from Mark.

The mysql driver class org.gjt.mm.mysql.Connection implements java.sql.Connection. As far as you use this interface to access the mysql connection, you can use ur code without modification for several database connections. The Connection for example returns an Statement, which is an abstract interface defining some services. In reality you will receive an object of type org.gjt.mm.mysql.Statement. But you shouldn't care about as long as you know this object which you receive implements java.sql.Statement.

This principle is called 'factory pattern'. You work with a set of interfaces and you don't care about the real implementation. A static 'factory' class chooses the specific implementation for your needs and returns the appropriate connection class (e.g. org.gjt.mm.mysql.Connection or oracle.jdbc.driver.OracleConnection ...). As long as your code only works with the java.sql interfaces you can quickly change (in theory) the database without modification of your code.

A> I also am developing a set of interfaces and abstract classes to manage A> very simply all my tables. I think I needed to build my own framework A> because the application I am currently developing needs to be used by A> people who don't have much confidence with computers, and the tables A> correlation MUST be maintained 24 hrs a day, 365 days a year. A> If anyone knows a strongly coherent and easy to use GUI interface (not A> for Administrators, I need to manage via GUI less than 30% of table A> data), please let me know. Well, Swing got a lot of goodies. Maybe try the RowSet classes of the javax.jdbc package (www.javasoft.com/jdbc). It's an bean-like abstraction of database tables. It follows strongly the JavaBeans spec and it's main use is for bean-composed application (especially for gui).

A> Thanks! No problem.

Stephan.