0
我正在使用Hibernate来访问我的数据库。我想删除一组标准函数的字段。我的数据库是PostgreSQL和我的Java代码是:从数据库中删除数据的问题
public void deleteAttr(String parameter){
Configuration cfg = new Configuration();
cfg.configure(resource.getString("hibernate_config_file"));
SessionFactory sessionFactory = cfg.buildSessionFactory();
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
tx.begin();
String sql = "delete from attribute where timestamp > to_date('"+parameter+"','YYYY-MM-DD')"
session.createSQLQuery(sql);
tx.commit();
}
该方法运行,但它不会从数据库中删除数据。我也检查了PgAdmin中的sql语句,它可以工作,但不能用代码。为什么?有人帮助我吗?
在此先感谢!
谢谢!当你说绑定命名参数时,你想说什么?我认为使用标准和限制类... –
阅读http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#objectstate-querying-executing-parameters。 –