package apollo;
/**
* SerializableJDBCConnection.java
*
*
* Created: Tue Aug 15 10:04:42 2000
*
* @author <a href="mailto: "Joe Kislo</a>
* @version
*/
import java.io.*;
import java.util.*;
import java.sql.*;
public class
SerializableJDBCConnection implements
Serializable, Connection {
private
String driverClassName;
private
String url;
private
Properties info;
private
String user;
private
String password;
private
transient
Connection c;
public
SerializableJDBCConnection (String driverClassName, String url) throws
ClassNotFoundException, IllegalAccessException, InstantiationException,
SQLException {
this.driverClassName=driverClassName;
this.url=url;
Class.forName(driverClassName).newInstance();
c = DriverManager.getConnection(url);
}
public
SerializableJDBCConnection (String driverClassName, String url, Properties info)
throws
ClassNotFoundException, IllegalAccessException, InstantiationException,
SQLException {
this.driverClassName=driverClassName;
this.url=url;
this.info=info;
Class.forName(driverClassName).newInstance();
c =
DriverManager.getConnection(url,info);
}
public
SerializableJDBCConnection (String driverClassName, String url, String user,
String password) throws
ClassNotFoundException, IllegalAccessException, InstantiationException,
SQLException {
this.driverClassName=driverClassName;
this.url=url;
this.user=user;
this.password=password;
Class.forName(driverClassName).newInstance();
c = DriverManager.getConnection(url,user,password);
}
 
private
void
writeObject(ObjectOutputStream out) throws
IOException {
out.writeObject(driverClassName);
out.writeObject(url);
out.writeObject(info);
out.writeObject(user);
out.writeObject(password);
}
private
void
readObject(ObjectInputStream in) throws
IOException, ClassNotFoundException {
driverClassName=(String) in.readObject();
url=(String) in.readObject();
info=(Properties) in.readObject();
user=(String) in.readObject();
password=(String) in.readObject();
try
{
System.out.println(driverClassName);
Class.forName(driverClassName).newInstance();
if
(info!=null)
{
c = DriverManager.getConnection(url, info);
} else
if
(user!=null
&& password!=null)
{
c = DriverManager.getConnection(url, user, password);
} else
{
c = DriverManager.getConnection(url);
}
} catch
(Exception e) {
System.out.println("JDBC
Serialization instantiation failed!");
e.printStackTrace();
}
}
protected
void
finalize() {
try
{
c.close();
} catch
(SQLException sqle) {}
}
public
Connection getConnection() {
return
c;
}
//Methods from
Connection
public
Statement createStatement() throws
SQLException {
return
c.createStatement();
}
public
PreparedStatement prepareStatement(String sql) throws
SQLException {
return
c.prepareStatement(sql);
}
public
CallableStatement prepareCall(String sql) throws
SQLException {
return
c.prepareCall(sql);
}
public
String nativeSQL(String sql) throws
SQLException {
return
c.nativeSQL(sql);
}
public
void
setAutoCommit(boolean
autoCommit) throws
SQLException {
c.setAutoCommit(autoCommit);
}
public
boolean
getAutoCommit() throws
SQLException {
return
c.getAutoCommit();
}
public
void
commit() throws
SQLException {
c.commit();
}
public
void
rollback() throws
SQLException {
c.rollback();
}
public
void
close() throws
SQLException {
c.close();
}
public
boolean
isClosed() throws
SQLException {
return
c.isClosed();
}
public
DatabaseMetaData getMetaData() throws
SQLException {
return
c.getMetaData();
}
public
void
setReadOnly(boolean
readOnly) throws
SQLException {
c.setReadOnly(readOnly);
}
public
boolean
isReadOnly() throws
SQLException {
return
c.isReadOnly();
}
public
void
setCatalog(String catalog) throws
SQLException {
c.setCatalog(catalog);
}
public
String getCatalog() throws
SQLException {
return
c.getCatalog();
}
public
void
setTransactionIsolation(int
level) throws
SQLException {
c.setTransactionIsolation(level);
}
public
int
getTransactionIsolation() throws
SQLException {
return
c.getTransactionIsolation();
}
public
SQLWarning getWarnings() throws
SQLException {
return
c.getWarnings();
}
public
void
clearWarnings() throws
SQLException {
c.clearWarnings();
}
public
Statement createStatement( int
resultSetType, int
resultSetConcurrency) throws
SQLException {
return
c.createStatement(resultSetType, resultSetConcurrency);
}
public
PreparedStatement prepareStatement(String sql, int
resultSetType, int
resultSetConcurrency) throws
SQLException {
return
c.prepareStatement(sql, resultSetType, resultSetConcurrency);
}
public
CallableStatement prepareCall(String sql, int
resultSetType, int
resultSetConcurrency) throws
SQLException {
return
c.prepareCall(sql, resultSetType, resultSetConcurrency);
}
public
Map getTypeMap() throws
SQLException {
return
c.getTypeMap();
}
public
void
setTypeMap(Map map) throws
SQLException {
setTypeMap(map);
}
}//
SerializableJDBCConnection