jdbc+mysql常见报错总结

1.The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must...

原因: 使用了Mysql Connector/J 6.x以上的版本,然后就报了时区的错误
解决办法: 在配置url的时候不能简单写成 :
jdbc:mysql://localhost:3306/jsp_text
而是要写成 :
jdbc:mysql://localhost:3306/jsp_text?serverTimezone=UTC

2. java.sql.SQLException: No value specified for parameter 1(多人多义,非唯一)

原因: 本人所用的数据库id并没有设置其主键自增功能,导致不能单传其他两个属性

    String sql_insert="";
    PreparedStatement pst=conn.prepareStatement("insert into user(title,content) values(?,?)");
pst.setString(1, request.getParameter("title"));
    pst.setString(2, request.getParameter("content"));


解决办法:在mysql数据库中设置此语句将id更改为自增,或者设置属性时选择“AI”(但是下方的auto increase框不能点)

ALTER TABLE `jsp`.`user`
CHANGE COLUMN `id` `id` int NOT NULL AUTO_INCREMENT ;

猜你喜欢

转载自www.cnblogs.com/zyddd915/p/12701781.html