BeanFactory.java
package two;
public class BeanFactory {
public JDBCInter createBean(String dbname){
JDBCInter jdbc = null;
if("sql".equals(dbname)){
return new MySQLJDBC();
}else if("mysql".equals(dbname)){
return new SqlJDBC();
}
return null;
}
}
BeanFactory01.java
package two;
public class BeanFactory01 {
public JDBCInter createBean(String dbname){
JDBCInter jdbc = null;
try {
jdbc = (JDBCInter)Class.forName(dbname).newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jdbc;
}
}
JDBCInter.java