package dk.hansen; import java.io.PrintWriter; import java.sql.*; import javax.sql.DataSource; /* * This is a factory for the CDManager DAO. It uses plain JDBC calls */ public class JdbcCDManagerFactory implements DatabaseCDManagerFactoryIF { private DataSource dataSource; public JdbcCDManagerFactory() throws DAOException { // Load the MySQL server JDBC driver String driverName = "org.gjt.mm.mysql.Driver"; try { Class.forName(driverName); } catch (ClassNotFoundException e) { throw new DAOException("JDBC Driver " + driverName + " could not be loaded"); } dataSource = new MyDataSource(); } public DataSource getDataSource() { return dataSource; } public CDManagerIF createCDManager() { DatabaseCDManager manager = new DatabaseCDManager(); manager.setDataSource(dataSource); return manager; } private class MyDataSource implements DataSource { public int getLoginTimeout() throws SQLException { return 0; } public void setLoginTimeout(int arg0) throws SQLException { } public PrintWriter getLogWriter() throws SQLException { return null; } public void setLogWriter(PrintWriter arg0) throws SQLException { } public Connection getConnection() throws SQLException { // Create a connection to the database String serverName = "localhost"; String mydatabase = "test"; String url = "jdbc:mysql://" + serverName + "/" + mydatabase; String username = ""; String password = ""; return DriverManager.getConnection(url, username, password); } public Connection getConnection(String arg0, String arg1) throws SQLException { return null; } } }