[英]MySql Java auto increment
I have a problem with the auto incremented values in preparedStatement. 我对prepareStatement中的自动递增值有问题。 Here is my database
这是我的数据库
CREATE TABLE `book` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`isbn` varchar(10) NOT NULL,
`title` varchar(20) NOT NULL,
`pages` int(11) NOT NULL,
`price` decimal(5,2) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `isbn` (`isbn`)
and here is my preparedStatement: 这是我的prepareStatement:
String title = fieldTitle.getText();
String isbn = fieldISBN.getText();
double price = Double.parseDouble(fieldPrice.getText());
int pages = Integer.parseInt(fieldPages.getText());
conn = DBUtil.connect();
try {
prepState = conn.prepareStatement("insert into book values(?,?,?,?)");
prepState.setString(1, isbn);
prepState.setString(2, title);
prepState.setInt(3, pages);
prepState.setDouble(4, price);
prepState.execute();
However, when I fill in the fields I get the following error: 但是,当我填写字段时,出现以下错误:
java.sql.SQLException: Column count doesn't match value count at row 1. I know that when the field in the database is autoincremented I do not have to put it in the query... java.sql.SQLException:列数与第1行的值数不匹配。我知道当数据库中的字段自动递增时,我不必将其放在查询中...
Any ideas? 有任何想法吗?
修改您的查询以包括列名称:-
INSERT INTO book (isbn, title, pages, price) VALUES (?,?,?,?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.