1、原本java插入數據庫表數據寫法是這樣的
String sql = "INSERT INTO AAA (id1,id2,id3,id4) VALUES ('1','2','3','4'); ";
baseDao.exexuteBySql(sql);
2、調用的baseDao.exexuteBySql方法是這樣的
public int exexuteBySql(String sql) throws Exception { try { log.debug("sql:{}", sql); SQLQuery query = null; Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession(); query = session.createSQLQuery(sql); return query.executeUpdate(); } catch (RuntimeException re) { log.error("exexuteBySql(String sql) ", re); throw re; } }
3、我的數據庫是oracle11g的,結果在執行的時候,報錯ORA-00911: 無效字符
4、去掉sql末尾的;號就可以了
String sql = "INSERT INTO AAA (id1,id2,id3,id4) VALUES ('1','2','3','4') ";
baseDao.exexuteBySql(sql);