1

SQL 语句在 MS Access 的查询设计中正常运行,但在 netbeans 代码中出现以下错误:

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] 参数太少。预计4。

我不知道这个错误消息的参数太少意味着什么,所以我不知道如何修复它。

任何有关我的代码为什么不起作用的帮助将不胜感激。

此类将数据库中的两个表作为一个 SQL 语句导入到两个数组中。

public class GuestArray
{
private Guest[] guest = new Guest[100];
private Reservations[] res = new Reservations[100];
private int size =0;
Connect conn = new Connect("GuestInfo.mdb");
public GuestArray()
{
    String sql = "SELECT GuestID, Title,Name,Surname,CountryLivingIn,"
    + "contactNumber,emailAddress,Day(checkInDate)AS idd, MONTH(checkInDate) AS imm,"
    + " YEAR(checkInDate) AS iYY, Day(checkOutDate)AS odd, MONTH(checkOutDate) AS omm, "
    + "YEAR(checkOutDate) AS oYY,RoomType,Adults,Children,Requests FROM ReservationDetails,"
    + "GuestDetails WHERE GuestDetails.GuestID=ReservationDetails.ReservationID";
    try
    {
        ResultSet rs = conn.query(sql);

        while(rs.next())
        {
            int id = rs.getInt("GuestID");
            String t = rs.getString("Title");
            String n = rs.getString("Name");
            String s = rs.getString("Surname");
            String c = rs.getString("CountryLivingIn");
            String num = rs.getString("contactNumber");
            String e = rs.getString("emailAddress");

            guest[size] = new Guest(id,t,n,s,c,num,e);

            int cid = rs.getInt("idd");//check-in-day
            int cim = rs.getInt("imm");//check-in-month
            int ciy = rs.getInt("iyy");//check-in-year
            int cod = rs.getInt("odd");//check-out-day
            int com = rs.getInt("omm");//check-out-month
            int coy = rs.getInt("oyy");//check-out-year
            String rt = rs.getString("RoomType");
            int ad = rs.getInt("Adults");
            int ch = rs.getInt("Children");
            String req = rs.getString("Requests");

            res[size] = new Reservations(id,t,n,s,c,num,e,cid,cim,ciy,cod,com,coy,rt,ad,ch,req);
            size++;                
        }
    }

    catch(Exception ex)
    {
            System.out.println("Error: "+ex);
    }
}
4

0 回答 0