Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL/Java error
    text
    copied!<p>Newbie programmer here. Upon doing mvn tomcat:run I get the following error:</p> <pre><code>SEVERE: Servlet.service() for servlet appServlet threw exception 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 'values (?, ?)' at line 1 </code></pre> <p>The code in question is as follows:</p> <pre><code>public void create(User user) { this.jdbcTemplate.update("INSERT INTO xyz.user(user_name, user_password values (?, ?)"); user.getUserName(); user.getId(); } public void delete(User user) { this.jdbcTemplate.update("DELETE FROM xyz.user WHERE id = ?"); } public void update(User user) { this.jdbcTemplate.update( "UPDATE xyz.user SET UserName = ? password = ? WHERE id = ?"); </code></pre> <p>Googled - couldn't find a solution for (?, ?) scenarios. Pls. help - Thx in advance :)</p> <p>Here's the complete code (almost) - I am doing something wrong but can't figure out what.</p> <pre><code>public User find(String login) { System.out.println("Trying to find the user...." + login); User user = this.jdbcTemplate.queryForObject( "select * from xyz where user_name = ?", new Object[]{login}, new RowMapper&lt;User&gt;() { public User mapRow(ResultSet rs, int rowNum) throws SQLException { User user = new User(); user.setId(Long.valueOf(rs.getInt(1))); user.setUserName(rs.getString(2)); user.setPassword(rs.getString(3)); return user; } }); System.out.println("Found user..." + user); return user; } public void create(User user) { this.jdbcTemplate.update("INSERT INTO ibstechc_dev.user(user_name, user_password) VALUES (?,?)"); user.getUserName(); user.getId() ; } public void delete(User user) { this.jdbcTemplate.update("DELETE FROM xyz WHERE id = ?"); // TODO Auto-generated method stub } public void update(User user) { this.jdbcTemplate.update( "UPDATE xyz SET user_name = ?, user_password = ? WHERE id = ?"); // TODO Auto-generated method stub } </code></pre> <p>}</p> <p>I am stuck with the same error - tomcat:run throws the following -</p> <pre><code>SEVERE: Servlet.service() for servlet appServlet threw exception </code></pre> <p>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 '?,?)' at line 1</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload