1、导入java.sql时The import java.sql cannot be resolved

首先保证你已经导入了mysql-connector-java-5.1.39-bin.jar包,此问题是导入jar之后才出现的,解决方法:修改项目包下的/FirstProject/src/module-info.java文件内容,FirstProject为我的项目名称。

导入java.sql时The import java.sql cannot be resolved及Unhandled exception type ClassNotFoundException处理

2、Class.forName("com.mysql.jdbc.Driver")这里出现Unhandled exception type ClassNotFoundException

若工程中未导入jdbc的jar包,到mysql官网下载压缩包,解压后导入工程中,下载解压之后

右击自己的工程,选择Build Path - Libraries - Add external Jars选择解压的jar包导入即可。

导入java.sql时The import java.sql cannot be resolved及Unhandled exception type ClassNotFoundException处理

导入之后还是出现问题解决方法:将Class.forName("com.mysql.jdbc.Driver")添加到异常捕捉机制中,如下图:

导入java.sql时The import java.sql cannot be resolved及Unhandled exception type ClassNotFoundException处理

相关文章:

  • 2021-09-25
  • 2021-08-08
  • 2021-05-06
  • 2021-12-16
  • 2021-12-17
猜你喜欢
  • 2021-04-21
  • 2021-08-27
  • 2021-12-16
  • 2021-11-14
  • 2022-12-23
  • 2021-10-28
  • 2021-08-31
相关资源
相似解决方案