You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

    1. First, double-check that mysql-connector-java-5.1.46-bin.jar is actually in your project's WEB-INF/lib folder (sometimes copy-paste operations don't work as expected).
    2. In NetBeans, expand your WebApplication1 project and look at the Libraries node. If the MySQL JAR isn't listed here, right-click on Libraries → Add JAR/Folder, then navigate to WEB-INF/lib and select the JAR file.
    3. Right-click the JAR in Libraries → Properties, and confirm the Scope is set to Compile (this ensures it's included during compilation and runtime).
  • Complete the Tools → Libraries configuration

    1. Go to NetBeans' top menu: Tools → Libraries.
    2. Click New Library, name it something like MySQL Connector/J 5.1.46, then click OK.
    3. Select your new library, go to the Classpath tab, click Add JAR/Folder, and select your mysql-connector-java-5.1.46-bin.jar file. Save the library.
    4. Back in your Web project, right-click Libraries → Add Library, choose the MySQL Connector/J 5.1.46 library 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:
      import com.mysql.jdbc.Driver;
      
      (Note: The com.mysql.cj.jdbc package is for MySQL Connector/J 8.x and later, so don't use that here.)
  • 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:04:28