javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181) org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1617) Util.SQLControl.insertOrderLine(SQLControl.java:66) Servlet.ShoppingCardServlet.processRequest(ShoppingCardServlet.java:53) Servlet.ShoppingCardServlet.doPost(ShoppingCardServlet.java:81) javax.servlet.http.HttpServlet.service(HttpServlet.java:660) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause:
org.hibernate.exception.SQLGrammarException: could not execute statement org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:178) org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:107) org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1632) org.hibernate.query.internal.NativeQueryImpl.doExecuteUpdate(NativeQueryImpl.java:295) org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1608) Util.SQLControl.insertOrderLine(SQLControl.java:66) Servlet.ShoppingCardServlet.processRequest(ShoppingCardServlet.java:53) Servlet.ShoppingCardServlet.doPost(ShoppingCardServlet.java:81) javax.servlet.http.HttpServlet.service(HttpServlet.java:660) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'pepsi' in 'field list' java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) com.mysql.jdbc.Util.handleNewInstance(Util.java:406) com.mysql.jdbc.Util.getInstance(Util.java:381) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542) com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937) com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922) org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:175) org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:107) org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1632) org.hibernate.query.internal.NativeQueryImpl.doExecuteUpdate(NativeQueryImpl.java:295) org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1608) Util.SQLControl.insertOrderLine(SQLControl.java:66) Servlet.ShoppingCardServlet.processRequest(ShoppingCardServlet.java:53) Servlet.ShoppingCardServlet.doPost(ShoppingCardServlet.java:81) javax.servlet.http.HttpServlet.service(HttpServlet.java:660) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note The full stack trace of the root cause is available in the server logs.
public void insertOrderLine(String orderName, String tableId, String pID, String pName , String category, int quantity, int price, String date){
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
Query query = session.createSQLQuery("INSERT INTO "+ orderName+" VALUES ("+tableId +","+ pID+" ,"+pName +
","+category+","+quantity+ ","+ price+" ,"+ date+")");
int result = query.executeUpdate();
}
Unknown column 'pepsi' in 'field list'
– RobOhRob