java.lang.ClassCastException:com.mysql.jdbc.JDBC4ResultSet无法转换为com.mysql.jdbc.ResultSet [英] java.lang.ClassCastException: com.mysql.jdbc.JDBC4ResultSet cannot be cast to com.mysql.jdbc.ResultSet

查看:86
本文介绍了java.lang.ClassCastException:com.mysql.jdbc.JDBC4ResultSet无法转换为com.mysql.jdbc.ResultSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Below shows an error message I am receiving when trying to run my code

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

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

I don't understand why this error is occurring so could someone give me the reason why or even better give me a fix to the problem. Below is the entire code

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;
}
}

推荐答案

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

You have to change your packages :- These are not right:

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

您可以使用此....

You can use this ....

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

因为您分别使用 java.sql 将连接用作 com.mysql 和DriverManager.这就是发生错误的原因.

because you are using connection as a com.mysql and DriverManager using java.sql like respectively. That is why the errors occurred.

这篇关于java.lang.ClassCastException:com.mysql.jdbc.JDBC4ResultSet无法转换为com.mysql.jdbc.ResultSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆