public User find(String username, String password) { Connection conn=null; PreparedStatement st=null; ResultSet rs=null;
try { conn=JdbcUtils.getConnection(); String sql="select * from users where username=? and password=?"; st=conn.prepareStatement(sql); st.setString(1,username); st.setString(2,password);
错误信息:2013-10-12 22:12:55 org.apache.catalina.startup.HostConfig checkResources 信息: Reloading context [/myday14_user] com.mysql.jdbc.exceptions.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 '?,?,?,?,?)' at line 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) at com.mysql.jdbc.Connection.execSQL(Connection.java:3277) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1402) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1317) at cn.itcast.dao.impl.UserDaoJdbcImpl.add(UserDaoJdbcImpl.java:32) at cn.itcast.service.impl.BusinessServiceImpl.registerUser(BusinessServiceImpl.java:25) at cn.itcast.web.controller.RegisterServlet.doGet(RegisterServlet.java:47) at cn.itcast.web.controller.RegisterServlet.doPost(RegisterServlet.java:67) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Unknown Source) 我实在没发现啊。。。我是对着写的呀 java exception mysql [解决办法]
executeUpdate
int executeUpdate(String sql) throws SQLException Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. Parameters: sql - an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement. Returns: either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing Throws: SQLException - if a database access error occurs, this method is called on a closed Statement or the given SQL statement produces a ResultSet object
ResultSet executeQuery() throws SQLException Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query. Returns: a ResultSet object that contains the data produced by the query; never null Throws: SQLException - if a database access error occurs; this method is called on a closed PreparedStatement or the SQL statement does not return a ResultSet object [解决办法] 那楼主问题解决了没有?没有报错ok了