我正在实现一个网络应用程序,用户需要使用他的数据库用户名和密码进行身份验证。 我想使用相同的输入用户名和密码连接到数据库。
换句话说,我希望 hibernate 配置文件中的这两个字段:(dbusername 和 dbpassword):
<property name="hibernate.connection.username">dbusername</property>
<property name="hibernate.connection.password">dbpassword</property>
可以根据输入用户名和密码登录 web 应用程序的用户动态填写。
这可行吗?
谢谢
最佳答案
这里是你如何实现的
Configuration cfg = new Configuration();
cfg.configure("hibernate.cfg.xml"); //hibernate config xml file name
String newUserName,newPassword;//set them as per your needs
cfg.getProperties().setProperty("hibernate.connection.password",newPassword);
cfg.getProperties().setProperty("hibernate.connection.username",newUserName);
sessionFactory = cfg.buildSessionFactory();
关于java - 以编程方式使用动态用户名和密码配置 Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18033288/