日期:2014-05-17  浏览次数:20709 次

看看这个问题:)
java.sql.SQLException: Too many parameters: expected 0, was given 6 Query: insert into book(name,author,price,image,description,category_id) Parameters: [我, 我我, 112, images/123453682068_550x550_0.jpg, 方芳芳, 1064ceb9-3ef8-462f-aa07-466a512a697c]


@Override
public void addBook(Book book) {
// TODO Auto-generated method stub
try {
QueryRunner runner = new QueryRunner(JDBCUtils.getDataSource());
String sql = "insert into book(name,author,price,image,description,category_id)";
Object[] params = {book.getName(),book.getAuthor(),book.getPrice(),book.getImageurl(),book.getDescription(),book.getCategory_id()};
runner.update(sql, params);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

------解决方案--------------------
Too many parameters: expected 0, was given 6
错误信息:Java认为这个SQL不需要参数,结果你给了6个参数。


String sql = "insert into book(name,author,price,image,description,category_id)";

语句没写完整,应该是:

String sql = "insert into book(name,author,price,image,description,category_id) values(?,?,?,?,?,?)";