简体   繁体   中英

import of java classes cannot be resolved

I am using eclipse for core java and its working fine. Now I downloaded another eclipse for java ee and I am using tomcat server but in my new eclipse java files are not getting loaded

Below mentioned imports are showing the error of import cannot be resolved while they are working fine in my old eclipse(I think there is some problem with build path ) -

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

While the below-mentioned imports do not show any error-

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.mysql.jdbc.ResultSet;

Sample Image of error:

在此处输入图片说明

检查您是否在IDE和项目中正确设置了JDK。

  1. A package at the top should be used, a deep src sub-directory like: src/aaa/bbb/ccc.

     package aaa.bbb.ccc; import ... 

    Reason: using the default package (immediately under the root) is actually never done since java 1.2. For that I find the missing package suspicious.

  2. The following is wrong:

     import com.mysql.jdbc.ResultSet; 

    It should be:

     import java.sql.ResultSet; 

    Reason for JDBC using database vendor specific libraries is bad style.

Entirely sure on a cause for your errors in eclipse I am not sure. A refresh, Alt+F5 might be useful if the error was a fluke.

If the JDK is actually java 9 I would expect import problems too, as then you would need to gather the JDK modules piecewise. That does not seem to be the case here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM