在学习Java的servlet过程中,学习到MySQL连接的部分时,配置都正确的情况下,一直没有得到想要的结果。网页这边一直是200,换浏览器也是200,但是就是空白,一点信息都没有,加上之前忘记MySQL的密码,苦苦思索一周时间了。
大致内容就是这些数据库的操作
很普通的数据库增删改查。
String sql="insert into test(name,account,password) values(?,?,?)";
//INSERT INTO `school`.`test` (`name`, `account`, `password`) VALUES ('李四', 'uwe', '123123');
ps=connection.prepareStatement(sql);
ps.setObject(1,"张三");
ps.setObject(2,"user001");
ps.setObject(3,"1234567");
int result=ps.executeUpdate();
Writer writer=response.getWriter();
writer.write("成功修改"+result+"条记录
");
writer.flush();
writer.close();
一开始在找[警告],把警告改差不多了,发现最重要的是异常。以下是几条警告:
在IntelliJ IDEA中,创建库lib,用来放入驱动程序,我之前用的是mysql-connector-java-5.1.18-bin.jar的,换这个mysql-connector-java-5.0.8-bin.jar即可。
下载地址参考这篇文章
https://goodluckpeng.blog.csdn.net/article/details/115376310?spm=1001.2014.3001.5502
mysql-connector-java-5.0.8-bin.jar下载地址放这里:
https://mvnrepository.com/artifact/mysql/mysql-connector-java
连接之后的代码如下所示,至于还有一个警告,目前还未解决。
Connected to server
[2022-08-18 07:36:31,273] Artifact webTest:war exploded: Artifact is being deployed, please wait…
18-Aug-2022 19:36:32.908 信息 [RMI TCP Connection(5)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[2022-08-18 07:36:33,140] Artifact webTest:war exploded: Artifact is deployed successfully
[2022-08-18 07:36:33,141] Artifact webTest:war exploded: Deploy took 1,867 milliseconds