我試圖執行休眠插入SQL查詢休眠插入不工作
String sqlQuery = "insert into examschedule (class_id,examtype_id,subject_id,examdate,start_time,end_time,messagetype_id,createddate) values";
String sql1 =sql1+ "("+ classes.getId()+","+
exType.getId()+","+
subjectName.getId()+","+
"'"+sqlDate+"'"+","+"'"+startTime+"'"+","+"'"+endTime+"'"+","+msgType.getId()+","+"'"+sqlTimestamp+"'"+");";
System.out.println(sqlQuery+sql1);
query = session.createSQLQuery(sqlQuery);
int result = query.executeUpdate();
SQL語句,但是,我得到異常下面當我試圖執行在MySQL控制檯相同的查詢,還有就是它完美地執行沒有語法錯誤
爲什麼在我調用createSQLQuery())查詢對象後,值參數會被刪除。
18:20:16,855 INFO [stdout] (http-localhost-127.0.0.1-8080-2) insert into examschedule (class_id,examtype_id,subject_id,examdate,start_time,end_time,messagetype_id,createddate) values(13,1,5,'2015-09-07','11AM','12PM',2,'2015-09-12 18:20:16.855');
18:20:16,868 INFO [stdout] (http-localhost-127.0.0.1-8080-2) Hibernate: insert into examschedule (class_id,examtype_id,subject_id,examdate,start_time,end_time,messagetype_id,createddate) values
18:20:16,871 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-2) SQL Error: 1064, SQLState: 42000
18:20:16,871 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http-localhost-127.0.0.1-8080-2) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
18:20:16,876 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) org.hibernate.exception.SQLGrammarException: could not execute statement
如果你只打算通過連接字符串來構建一個查詢,爲什麼還要打擾hibernate呢? – e4c5