找不到DriverManager,红色下划线并提示我创建类DriverManager

问题描述 投票:0回答:1
protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
    //define the fields
    String username = "root";
    String password = "Otiwah0771";
    String jdbcURL = "jdbc:mysql://localhost:3306/employeedirectory";
    String driver = "com.mysql.jdbc.Driver";

    try
    {

    //Get the Print Writer object
    PrintWriter out = response.getWriter();
    out.println("Connecting to databace"+jdbcURL);

    //load the Driver 
    Class.forName(driver);

    //Get the connection
    Connection connection = DriverManager.getConnection(jdbcURL,username,password);

    //Close the connection
    connection.close();
    }catch(Exception e)
    {
        e.printStackTrace();
    }
}

**使用Netbeans 11.2 **

我已添加mysql连接器jar,但问题仍然存在(找不到DriverManager符号)

mysql jdbc
1个回答
-1
投票

问题是jdbc-api-1.4.jar不属于库,因此无法导入java.sql.Driver.class。从jdbc api下载jdbc-api-1.4.jar-将其添加到库中,就可以使用

© www.soinside.com 2019 - 2024. All rights reserved.