在操作时代码如下: public void addSample(Sample s) {
// 1 get the attributes of sample object
String name = s.getName();
String hobby = s.getHobby();

String sql = "insert into sample values(null,?,?)";
Connection con = JdbcUtils.getConn();
PreparedStatement pstmt = null;
try {
 pstmt = con.prepareStatement(sql);
 pstmt.setString(1, name);
 pstmt.setString(2, hobby);
 JdbcUtils.add(pstmt, con, sql);
} catch (SQLException e) {
e.printStackTrace();


// 2 create sql statement and execute
}
在JSP中输入数值,通过servlet调用上面的方法
数据表结构是 id | name | hobyytomcat 报错:
no value specified for parameter 1不知道是不是不允许空值的原因,id那一列是主键,自动递增。