PreparedStatement pstmt = conn.prepareStatement(sql);有错误

PreparedStatement pstmt = conn.prepareStatement(sql);
提示:The method prepareStatement(String) is undefined for the type Connection错误,为什么?

很可能是字段类型不匹配造成的。假设你的表里有label_id字段,这个字段在数据库的类型是int,而你在SQL插入语句里给他赋值用了字符串,那就会报错。这个错误很隐秘,不过用try..catch方法也能得到错误提示。