1
我試圖改變hibernate.cfg.xml文件編程 這裏的屬性是我所做的:如何更改cfg.xml文件的屬性?
public class NewHibernateUtil {
private final SessionFactory sessionFactory;
String host;
String database;
String username;
String password;
NewHibernateUtil(String host,String database,String username,String password){
this.host=host;
this.database=database;
this.username=username;
this.password=password;
AnnotationConfiguration ac=new AnnotationConfiguration().configure();
ac.setProperty("connection.url", "jdbc:mysql://"+host+"/"+database+"");
ac.setProperty("connection.username", username);
ac.setProperty("connection.password", password);
sessionFactory = ac.buildSessionFactory();
}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
}
但是這不起作用,它總是使用老樓盤在hibernate.cfg .xml文件。
非常感謝你,問題就迎刃而解了:d – Walllzzz