Note that there are some explanatory texts on larger screens.

plurals
  1. POJdbcTemplate, MySQL error
    primarykey
    data
    text
    <p>Need Help! I have asked a question here earlier - <a href="https://stackoverflow.com/questions/18307358/mysql-java-error">MySQL/Java error</a> related to this one but not identical (not sure of the protocols at SO for such questions). I am working with JDBC, MySQL and encountering errors. First, the code</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 xyz (user_name,user_password) VALUES (default, default, ?, ?)", new Object[] {user.getUserName(),user.getPassword()}); </code></pre> <p><em>I need to give default values to user_name, user_password (the 2 columns) but don't know how and where in the "create(User user) block.</em></p> <p>Here's the error for the code above:</p> <pre><code>SEVERE: Servlet.service() for servlet appServlet threw exception java.sql.SQLException: Column count doesn't match value count at row 1 </code></pre> <p>I have tried it without 'default', 'default' and just (?, ?) but that gives me yet another 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 '?,?)' at line 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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