It would go something like this: In Helperclass.java you would have:
public static Connection getConnection (
String url, String user, String password) {
try {
return DriverManager.getConnection( url, user, password );
} catch( Exception x ) {
System.err.println( x );
return null;
}
and then in your application:
static {
try {
Class.forName( driver ).newInstance("com.mysql.jdbc.Driver");
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
}
and later on
Connection con = Helperclass.getConnection(url, user, password);
// do something with con; of course, it could be null!
If the URL is always the same (i.e., you're using the same DB all the time), you could have the helper class take care of that as well.
[ August 09, 2005: Message edited by: Ulf Dittmer ]