我想創建使用休眠準備語句的新表。它看起來像"setparameter("values", value)"
添加額外的引號來查詢。 我的代碼:休眠setParameter字符串添加單引號
String hql = "create table :values " + "(name VARCHAR(50))";
Query my = session.createSQLQuery(hql);
my.setParameter("values", value);
my.executeUpdate();
session.close();
錯誤:
SEVERE: Servlet.service() for servlet [contextServlet] in context with path [/SpringSafeHouseService2.0] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 ''merkurijuss' (name VARCHAR(50))' at line 1
您可以使用表名作爲參數在事先準備好的聲明 – Jens