下面显示了尝试运行代码时收到的错误消息

java.lang.ClassCastException: com.mysql.jdbc.JDBC4ResultSet cannot be cast to com.mysql.jdbc.ResultSet


我不明白为什么会发生此错误,所以有人可以告诉我原因,甚至更好地为我解决问题的原因。下面是完整的代码

package com.hotel.database;


import com.hotel.beans.VehicleTypeBean;


import java.sql.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Vector;
import com.hotel.beans.ReservationDetailsBean;
import com.hotel.beans.AgentBean;
import com.hotel.beans.CheckInBean;
import com.hotel.beans.CompanyBean;
import com.hotel.beans.CustomerBean;
import com.hotel.beans.RecieptBean;
import com.hotel.beans.ReservationBean;
import com.hotel.beans.RoomClassBean;
import com.hotel.beans.RoomRateBean;
import com.hotel.beans.RoomStatusBean;
import com.hotel.beans.TransportRecieptBean;
import com.hotel.beans.TransportfareBean;
import com.hotel.beans.VehicleBean;
import com.hotel.beans.VehicleDriverBean;
import java.sql.Date;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Vector;
/**
 *
 * @author lenovo
 */
public class Transport {
     Connection conn=null;
    ResultSet rs=null;
    PreparedStatement stmt=null;
    private Vector v;
    private LinkedList[] lst;
    private int stId;
    private Statement state;
    private ResultSet res;
    public Transport(){
         conn=ConnectionProvider.getConnection();
    }
public LinkedList [] getWalkInGuests()throws Exception
        {
           int count=0;
stmt=(PreparedStatement) conn.prepareStatement("select count(distinct customerId) from transport where reservationId=-1");
rs=(ResultSet) stmt.executeQuery();
    if(rs.next())
    {
    count=rs.getInt(1);
    }
    lst=new LinkedList[count];
        if(lst.length<1)
            return lst;
    count=0;
   stmt=(PreparedStatement) conn.prepareStatement("SELECT customer.customer_id,customer.firstName,customer.lastName,customer.address from customer where customer.customer_id IN (select customerId from transport where reservationid=-1)");
         // stmt.setInt(1, )
    rs=(ResultSet) stmt.executeQuery();
    while(rs.next())
    {
        lst[count]=new LinkedList();
        lst[count].add(rs.getInt("customer.customer_id"));
        lst[count].add(rs.getString("customer.firstName"));
        lst[count].add(rs.getString("customer.lastName"));
    lst[count].add(rs.getString("customer.address"));
     count++;
    }
    return lst;
}
}

最佳答案

您必须更改软件包:-这些不正确:

import com.mysql.jdbc.DriverManager;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;


您可以使用此....

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;


因为您分别使用java.sql之类的连接作为com.mysql和DriverManager。这就是为什么发生错误。

07-28 14:20