我想选择最后一个生成的ID,但我却得到无效的参数值:java.io.NotSerializableException 原因:java.io.NotSerializableException:model.Category
这是插入代码
public static void add_product(Product product) {
Connection cnx;
long key = -1L;
cnx = Connect.getConnection();
String req = "insert into product(name, category) values(?,?)";
PreparedStatement st = cnx.prepareStatement(req, Statement.RETURN_GENERATED_KEYS);
st.setString(1, product.getName());
st.setObject(2, product.getCategory());
st.executeUpdate();
ResultSet rs = st.getGeneratedKeys();
if (rs.next()) {
key = rs.getLong(1);
}
}
这是servlet代码
String name = request.getParameter("name");
int id_category = Integer.parseInt(request.getParameter("category"));
Category category = DAO.get_category(id_category );
Product p = new Product (name, category);
DAO.add_product(p);
原因:java.io.NotSerializableException:model.Category
java.io.ObjectOutputStream.writeObject0上的(未知源) 在java.io.ObjectOutputStream.writeObject(未知来源) 在com.mysql.jdbc.PreparedStatement.setSerializableObject(PreparedStatement.java:44