Windows10下NetBeans8.2报错package com.mysql does not exist 求助
Fixing "package com.mysql does not exist" in NetBeans 8.2 Web Project (Windows 10)
Hey there, let's tackle that frustrating error you're seeing. You've already made some progress by adding the MySQL Connector JAR to WEB-INF/lib and starting to configure libraries—let's finish that up and get your project running smoothly.
Here are the step-by-step fixes to try:
Verify the JAR is properly recognized in your project
- First, double-check that
mysql-connector-java-5.1.46-bin.jaris actually in your project'sWEB-INF/libfolder (sometimes copy-paste operations don't work as expected). - In NetBeans, expand your
WebApplication1project and look at the Libraries node. If the MySQL JAR isn't listed here, right-click on Libraries → Add JAR/Folder, then navigate toWEB-INF/liband select the JAR file. - Right-click the JAR in Libraries → Properties, and confirm the Scope is set to
Compile(this ensures it's included during compilation and runtime).
- First, double-check that
Complete the Tools → Libraries configuration
- Go to NetBeans' top menu: Tools → Libraries.
- Click New Library, name it something like
MySQL Connector/J 5.1.46, then click OK. - Select your new library, go to the Classpath tab, click Add JAR/Folder, and select your
mysql-connector-java-5.1.46-bin.jarfile. Save the library. - Back in your Web project, right-click Libraries → Add Library, choose the
MySQL Connector/J 5.1.46library you just created, and click Add. This ensures the IDE properly references the driver across your project.
Clean and rebuild your project
- NetBeans sometimes holds onto old cached files that cause dependency issues. Go to Build → Clean and Build Project (WebApplication1). This will wipe old compiled files and rebuild the project with your updated dependencies.
Check your import statements
- Make sure your Java classes are using the correct import for the MySQL driver. Since you're using version 5.1.46, the import should be:
(Note: Theimport com.mysql.jdbc.Driver;com.mysql.cj.jdbcpackage is for MySQL Connector/J 8.x and later, so don't use that here.)
- Make sure your Java classes are using the correct import for the MySQL driver. Since you're using version 5.1.46, the import should be:
Restart NetBeans (if needed)
- If you've tried all the above and still see the error, restarting NetBeans can clear any lingering IDE cache that's preventing the driver from being recognized.
If you follow these steps, that "package com.mysql does not exist" error should disappear, and you'll be able to work with your MySQL database in your web project.
内容的提问来源于stack exchange,提问作者smbelow
相关产品推荐
相关产品推荐

