Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 1338
Alex Hales
  • 0
Alex HalesTeacher
Asked: May 30, 20222022-05-30T13:09:33+00:00 2022-05-30T13:09:33+00:00

Java/sql Hotel Database Setting DATE as a parameter in java

  • 0

[ad_1]

I am trying to Create a SQL Booking by using variables like adults booked customerid children booked ,check-in and check-out date however when i try to input date into the java code to create a booking i keep getting the error error: incompatible types: int cannot be converted to Date book.CreateBooking(5 , 1 , 2 , 2022-04-21 , 2022-04-24 ); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 1 error

This a school assignment due in a day, and i cant get over this createbooking section

My Code

import java.sql.* ;
import java.util.Date;

public class Booking
{
  private int iBookingID;
  private int iCustomerID;
  private int iAdultsBooked;
  private int iChildrenBooked;
    private Date szCheckIn;
    private Date szCheckOut;
  private int iNumRows ;

    // DB materials.
    private String sql ;
    private String sz ;

    private Statement sqlStatement = null ; 
    private ResultSet resultSet = null ;
  private Session dbSession ;

  public Booking()
  {
    reset() ;
    this.dbSession = new Session() ;
        dbSession.connect();
        if ( dbSession.isConnected() == false )
        {
            System.err.println( this.getClass().getName() + ":: failed to connect to DB for table." ) ;
        }
        countRows() ;
    return ;
  }

  protected void reset()
  {
    iNumRows = -1 ;     // to spot the difference between empty table & no methods run.
        sz = null ;
        sql = null ;
        sqlStatement = null ;
        resultSet = null ;
    return ;

  }

  // Setters
  public void setAdultsBooked (int iAdultsBooked)
  {
    this.iAdultsBooked = iAdultsBooked ;
  }

  public void setChildrenBooked (int iChildrenBooked)
  {
    this.iChildrenBooked = iChildrenBooked ;
  }

     public void setCheckIn (Date szCheckIn)
  {
    this.szCheckIn = szCheckIn ;
  }

    public void setCheckOut (Date szCheckOut)
  {
    this.szCheckOut = szCheckOut ;
  }

  public void setCustomerID (int iCustomerID)
  {
    this.iCustomerID = iCustomerID ;
  }

    
  public void setBookingID (int iBookingID)
  {
    this.iBookingID = iBookingID ;
  }


  // Getters

 public int getAdultsBooked ()
  {
    return this.iAdultsBooked ;
  }

     public int getChildrenBooked ()
  {
    return this.iChildrenBooked ;
  }

    public Date getCheckOut ()
  {
    return this.szCheckOut ;
  }

    public Date getCheckIn ()
  {
    return this.szCheckIn ;
  }

    
     public int getCustomerID ()
  {
    return this.iCustomerID ;
  }

        
    public int getBookingID ()
  {
    return this.iBookingID ;
  }


    //Create Booking

  public boolean CreateBooking(int iCustomerID, int iAdultsBooked, int iChildrenBooked, Date szCheckOut, Date szCheckIn )
  {
        
        boolean bRC = false ;
        clearAttributes() ;

    this.setCustomerID(iCustomerID);
        this.setAdultsBooked(iAdultsBooked);
        this.setChildrenBooked(iChildrenBooked);
        this.setCheckIn(szCheckIn);
        this.setCheckOut(szCheckOut);

        bRC = this.CreateBooking() ;
        return ( bRC ) ;
  }

    public boolean CreateBooking()
    {
        boolean bRC = false ;
        int iRC ;
        try
        {
            System.err.println( this.getClass().getName() + ":: DB connected := " + dbSession.isConnected() ) ;

            sql = "INSERT INTO Bookings( "
                + "  CustomerID"
                    + ", AdultsBooked"
                    + ", ChildrenBooked"
                    + ", Check_In"
                    + ", Check_Out"
                    + " ) "
                    + " VALUES( "
                    + "  \"" + this.getCustomerID()  + "\""
                    + ", \"" + this.getAdultsBooked()  + "\""
                    + ", \"" + this.getChildrenBooked() + "\""
                    + ", \"" + this.getCheckIn() + "\""
                    + ", \"" + this.getCheckOut() + "\""
                    + " ) ; " ;

        sqlStatement = dbSession.getConnection().createStatement() ;
            iRC = sqlStatement.executeUpdate( sql ) ;
            
        return ( bRC ) ;
    }


 public void display()
    {

    sql = "SELECT * FROM Bookings;" ;

        sz = "::display()\n" ;
      sz = sz + "\n\tBookingID := " + getBookingID() ;
      sz = sz + "\n\tCustomerID := " + getCustomerID() ;
        sz = sz + "\n\tAdultsBooked := " + getAdultsBooked() ;
    sz = sz + "\n\tChildrenBooked := " + getChildrenBooked() ;
    sz = sz + "\n\tCheck_Out := " + getCheckOut() ;
    sz = sz + "\n\tCheck_In := " + getCheckIn() ;
    
        System.out.println( this.getClass().getName() + sz ) ;
        return ;
    }



  //----------------------------------------------------------------------
    // test rig
    //----------------------------------------------------------------------
    public static void main( String [] args )
    {

        Booking book = new Booking();
    book.CreateBooking(5 , 1 , 2 , 2022-04-21 , 2022-04-24 );
    book.display();
    return;
  }

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 4778 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1063 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1009 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.