2014-03-13 17 views
1

所以,我在我的項目中使用Spring,用JDBC來管理數據庫部分。奇怪org.springframework.jdbc.BadSqlGrammarException

當一個人試圖註冊,填寫表格後,這種方法被稱爲:

@Override 
public String addUser(Usuario user) { 
public static String SQLADDUSER="insert into users(NOMBRE, PASSWORD, EMAIL, NEWSLETTER) values=(?,?,?,?)"; 
    getJdbcTemplate().update(SQLADDUSER,new Object[]{user.getNombre(), user.getPass(), user.getEmail(),user.isNewsletter()}); 
    return "ok"; 
} 

我有一些sysouts那裏看到user.getNombre(),等等不爲空。他們有合適的價值。

我在數據庫中有一些其他模式(我正在使用MySQL),其中一個標記爲默認模式。但是,在這個應用程序的其他部分,我從用戶那裏做了select *,並且用戶很好地返回。

我這樣宣佈我的數據源豆:

<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <beans:property name="driverClassName" value="com.mysql.jdbc.Driver"></beans:property> 
    <beans:property name="url" value="jdbc:mysql://localhost:3306/theproperschema"></beans:property> 
    <beans:property name="username" value="root"></beans:property> 
    <beans:property name="password" value="root"></beans:property> 
</beans:bean> 
<beans:bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 
    <beans:property name="dataSource" ref="dataSource"></beans:property> 
</beans:bean> 

表用戶已經4列一旁id列(主鍵)的,:農佈雷,傳遞,電子郵件(這三個是VARCHAR)和通訊(是一個二進制文件)。

而且,當我嘗試插入這個,我有這樣的例外:

Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [insert into users(NOMBRE, PASSWORD, EMAIL, NEWSLETTER) values=(?,?,?,?)]; nested exception is 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 '=('jarl','nopuedor','tedacuen',1)' at line 1] con causa raíz 
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 '=('jarl','nopuedor','tedacuen',1)' at line 1 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) 
at com.mysql.jdbc.Util.getInstance(Util.java:381) 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030) 
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) 
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) 
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) 
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) 
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542) 
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937) 
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922) 
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:818) 
at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:1) 
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:587) 
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:812) 
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:868) 
at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:876) 
at my.package.Dao.UserDaoImp.addUser(UserDaoImp.java:59) 
at my.package.Services.UsuarioServiceImp.addUser(UsuarioServiceImp.java:44) 
at my.package.Controllers.NewUserFormController.addUsuario(NewUserFormController.java:37) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:606) 
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) 
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) 
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) 
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) 
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) 
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) 
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) 
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) 
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) 
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) 
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
at java.lang.Thread.run(Thread.java:744) 

我不知道哪裏出錯。任何幫助?

回答

1

你不需要等號=在您的SQL查詢

insert into users(NOMBRE, PASSWORD, EMAIL, NEWSLETTER) values=(?,?,?,?) 

只要寫這個代替

insert into users(NOMBRE, PASSWORD, EMAIL, NEWSLETTER) values(?,?,?,?) 
+0

...林慚愧。當然,它的工作。謝謝,當我能做到的時候,我會努力... – Fustigador

+0

它發生了。沒有什麼可羞恥的;) – TheEwook