跟着视频做个很简单的数据库连接和关闭,结果出现这个错误,网上找了一堆没跟我一样的。。。
错误提示
The method close() is undefined for the type Resultset
代码如下
package com.zkz.magSystem.com;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.mysql.cj.protocol.Resultset;
public class BaseDAO {
public static Connection getConnection() throws Exception{
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://localhost:3306/exam","root","12345");
}
public static void close(Connection conn,PreparedStatement ps,Resultset rs){
try {
if(rs != null) rs.close();
if(ps != null) ps.close();
if(conn !=null && !conn.isClosed()) conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}