我的mysql中有个product表:
create table product
(
product_id int primary key auto_increment,
product_name varchar(50),
product_category varchar(30),
product_counter int,
product_new_degree int,
product_descr varchar(255),
product_enter_time datetime,
product_price double,
product_isBargin int,
product_shop_id int references shop(shop_id)
);
现在我用的SQL语句
String sql="insert into product(product_name,product_category,product_counter,product_new_degree,product_descr,product_enter_time,product_price,product_isBargin,product_shop_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)";tomcat怎么会提示我这个错误:
Unkown colum 'product_name' in 'field list'
create table product
(
product_id int primary key auto_increment,
product_name varchar(50),
product_category varchar(30),
product_counter int,
product_new_degree int,
product_descr varchar(255),
product_enter_time datetime,
product_price double,
product_isBargin int,
product_shop_id int references shop(shop_id)
);
现在我用的SQL语句
String sql="insert into product(product_name,product_category,product_counter,product_new_degree,product_descr,product_enter_time,product_price,product_isBargin,product_shop_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)";tomcat怎么会提示我这个错误:
Unkown colum 'product_name' in 'field list'
PreparedStatement pstmt=Opendb.prepare(con,sql);
try{
pstmt.setString(1, product_name);//把宝贝信息插入数据库
pstmt.setString(2, product_category);
pstmt.setInt(3, Integer.parseInt(product_counter));
pstmt.setInt(4, Integer.parseInt(product_new_degree));
pstmt.setString(5, product_descr);
pstmt.setTimestamp(6, new Timestamp(d.getTime()));
pstmt.setDouble(7, Double.parseDouble(product_price));
pstmt.setInt(8, Integer.parseInt(product_isBargin));
pstmt.setInt(9, shop_id_2);
pstmt.executeUpdate();
%>
上传宝贝成功...
<%
}catch(SQLException e){
e.printStackTrace();
}finally {
Opendb.close(pstmt);
Opendb.close(con);
}
大家帮忙看看,感激不尽...
给个建议
pstmt.setString(1, product_name);//把宝贝信息插入数据库
其中数字用变量来代替
int seq = 1
pstmt.setString(seq++, product_name);
pstmt.setString(seq++, product_category);
这样不需要管有多少参数,要是添加个字段也不用改数字那么麻烦了
肯定是字段名写错了啊