W
Wiseguy
ok. so I know that I cannot (extend) an interface but I got your
attention.
Consider the following:
public class DBconnection {
public Connection conn;
public boolean error=false;
public DBconnection() {
String URL=new String("jdbcostgresql://localhost/mydatabase");
String UNAME=new String("me");
String PASSWD=new String("");
String DRIVER=new String("org.postgresql.Driver");
try {URL=new String(System.getProperty("URL"));}
catch (Exception e) {}
try {UNAME=new String(System.getProperty("UNAME"));}
catch (Exception e) {}
try {PASSWD=new String(System.getProperty("PASSWD"));}
catch (Exception e) {}
try {DRIVER=new String(System.getProperty("jdbc.drivers"));}
catch (Exception e) {}
try {
Class.forName(DRIVER);
// load the driver classes
conn=DriverManager.getConnection(URL,UNAME,PASSWD);
// get a connection
}
catch (Exception e) {
System.out.println("-- Cannot access DB --");
System.out.println("jdbc.drivers='"+DRIVER+"'");
System.out.println("URL='"+URL+"'");
System.out.println("UNAME='"+UNAME+"'");
System.out.println("PASSWD='"+PASSWD+"'");
System.out.println("Exception is:"+e.toString());
System.out.println("----------------------");
error=true;
}
}
Having to reference the (conn) member to get a connection is a needless
step. I'd like the above class to implement the Connection interface for
the postgres driver so that the DBConnection object can be used anywhere
that a normal Connection is used.
Here's the booger though. Completely implementing the Connection
interface in the DBconnection class is a hell-of-a-lot of coding. Isn't
there a quicker way to make the DBConnection contain the functionality of
Connection without actually implementing it?
attention.
Consider the following:
public class DBconnection {
public Connection conn;
public boolean error=false;
public DBconnection() {
String URL=new String("jdbcostgresql://localhost/mydatabase");
String UNAME=new String("me");
String PASSWD=new String("");
String DRIVER=new String("org.postgresql.Driver");
try {URL=new String(System.getProperty("URL"));}
catch (Exception e) {}
try {UNAME=new String(System.getProperty("UNAME"));}
catch (Exception e) {}
try {PASSWD=new String(System.getProperty("PASSWD"));}
catch (Exception e) {}
try {DRIVER=new String(System.getProperty("jdbc.drivers"));}
catch (Exception e) {}
try {
Class.forName(DRIVER);
// load the driver classes
conn=DriverManager.getConnection(URL,UNAME,PASSWD);
// get a connection
}
catch (Exception e) {
System.out.println("-- Cannot access DB --");
System.out.println("jdbc.drivers='"+DRIVER+"'");
System.out.println("URL='"+URL+"'");
System.out.println("UNAME='"+UNAME+"'");
System.out.println("PASSWD='"+PASSWD+"'");
System.out.println("Exception is:"+e.toString());
System.out.println("----------------------");
error=true;
}
}
Having to reference the (conn) member to get a connection is a needless
step. I'd like the above class to implement the Connection interface for
the postgres driver so that the DBConnection object can be used anywhere
that a normal Connection is used.
Here's the booger though. Completely implementing the Connection
interface in the DBconnection class is a hell-of-a-lot of coding. Isn't
there a quicker way to make the DBConnection contain the functionality of
Connection without actually implementing it?