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 a 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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6944051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:14:08+00:00 2026-05-27T13:14:08+00:00

This code has caused me lots of trouble so far but it’s really first

  • 0

This code has caused me lots of trouble so far but it’s really first class I write to use preparedStatement, Oracle, and serialization. So I am asking for your patience.
The following is the code:

 public static boolean storeInfo(Reservation rsv) throws
        IOException, SQLException{
    try {
          //Connection to DB
          Connection con = null;
          Class.forName("oracle.jdbc.driver.OracleDriver");
          con=DriverManager.getConnection(
            "jdbc:oracle:thin:@odsdsd",
            "SMBDB",
            "hpdbsmb");
          con.setAutoCommit(false);
          ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
          ObjectOutputStream out = new ObjectOutputStream(bos);
          out.writeObject(rsv);
          out.flush();
          out.close();
          byte[] buf = bos.toByteArray();
          //inserting into database
          PreparedStatement prepareStatement = con.prepareStatement("INSERT INTO 
           SMD_RESERVATION_INSTANCES VALUES(?,?,?)");
          localIDTest = getUniqueID();
          System.out.println("ID: "+localIDTest);
          prepareStatement.setString(1, localIDTest);
          prepareStatement.setBytes(2, buf);
          prepareStatement.setString(3, "Pending");
          prepareStatement.executeUpdate();
          prepareStatement.close();
          con.commit();
   }catch(SQLException sqle){
       System.err.print(sqle);
   }
   catch(ClassNotFoundException cnfe){
       System.err.print(cnfe);
   }
    return false;
   }


   public static Reservation retrieveReservation()throws IOException,
        SQLException{
   Reservation testRsv = new Reservation();
   try {
        Connection con = null;

        Class.forName("oracle.jdbc.driver.OracleDriver");
        con=DriverManager.getConnection(
            "jdbc:oracle:thin:@dsdsds",
            "SMBDB",
            "hpdbsmb");
        con.setAutoCommit(false);
       try {

            PreparedStatement prepareStatement = con.prepareStatement("SELECT * FROM 
             SMD_RESERVATION_INSTANCES WHERE id = ?");         
            prepareStatement.setString(1, localIDTest);
            ResultSet rset = prepareStatement.executeQuery();
            prepareStatement.executeUpdate();
            //prepareStatement.close();
            con.commit();
            if(rset.next()){
                retrievedID = rset.getString("ID");
                Blob blob = rset.getBlob("RESERVATIONINST");
                status = rset.getString("STATUS");
                long blobLength = blob.length();
                int pos = 1;   // position is 1-based
                //int len = 10;
                byte[] bytes = blob.getBytes(pos,(int) blobLength);
                InputStream is = blob.getBinaryStream();
                ObjectInputStream ois = new ObjectInputStream(is);
                testRsv=(Reservation)ois.readObject();
            }


        rset.close();
        con.close();
         }catch(IOException ioe){
              System.err.print(ioe);
          }
       }catch(ClassNotFoundException cnfe){
          System.err.print(cnfe);
      }
    return testRsv;

   }

   public static void displayRsvContent(){

    try{
        Reservation rsvtester = new Reservation();
        rsvtester.badgeNo = 750752;
        rsvtester.networkID = "GHAMKS1C";
        storeInfo(rsvtester);
        rsvReturned = retrieveReservation();
        if(rsvReturned == null){
            System.out.println("Null Reservation!");
        }else{
            System.out.println("Badge: " + rsvReturned.badgeNo);
            System.out.println("Network: " + rsvReturned.networkID);
        }

    }catch(SQLException sqle){
            System.err.print(sqle);
    }catch(IOException ioe){
        System.err.print(ioe);
    }
  }


public static void main(String[]args){
    displayRsvContent();
}

This is just testing that storing and retrieving the object is done correctly. I create an instance of Reservation and assign its variables values to see if they are actually saved. Surprise surprise they aren’t showing up when loading. This is what I get:

ID: ec561507-7138-4468-98a3-7756219f216e
Badge: 0
Network: null

Why is this happening even though am simply assigning it before storing the object? The id shows though is correct.

P.S. Reservation:

public class Reservation implements
   java.io.Serializable{

String eventTitle;
public Date startDate;
public Date endDate;
String requestType;
public int terminals;
String lastName;
String firstName;
String middleInitials;
public transient int badgeNo;
public transient String networkID;
String telephoneNo;
String orgCode;
String orgName;
String justification;
String insideCheckRange;
int mapSize;



MapStorage mapStorage = new MapStorage();


public Reservation(int badgeNo, String networkID) {
    this.badgeNo = badgeNo;
    this.networkID = networkID;
}


    public Reservation(){

    }

public Reservation(String eventTitle, Date startDate, Date endDate, String requestType, int terminals, String lastName, String firstName, String middleInitials, int badgeNo, String networkID, String telephoneNo, String orgCode, String justification) {
    //create in here

    this.eventTitle = eventTitle;
    this.startDate = startDate;
    this.endDate = endDate;
    this.requestType = requestType;
    this.terminals = terminals;
    this.lastName = lastName;
    this.firstName = firstName;
    this.middleInitials = middleInitials;
    this.badgeNo = badgeNo;
    this.networkID = networkID;
    this.telephoneNo = telephoneNo;
    this.orgCode = orgCode;
    this.justification = justification;
}



 public boolean checkRange() {    



        DateTime startx = new DateTime(startDate.getTime());
        DateTime endx = new DateTime(endDate.getTime());

        //booking status
        boolean possible = false;

        //Booking type: 1 = Project, 2 = Training

        /*
        if(requestType.equals("Project")){
            bookingType = 1;
        }else if(requestType.equals("Training")){
            bookingType = 2;

        }
        */
        //produces submap
        //mapSize = bookingType;
        TreeMap<DateTime, Integer> mapLoaded = null;
        try{
         mapLoaded = mapStorage.RetrieveMap();
        }catch(IOException ioe)
        {
            System.err.print(ioe);
        }
        if(requestType.equals("Project"))
        {
            //Project
            //insideCheckRange = "In first for loop";
            //fetch all values for keys in the map between start and end
                for (Integer capacity : mapLoaded.subMap(startx, endx).values()) {


                    if(capacity >= terminals)
                        //yes then its possible, set to true
                        possible = true;
                    else if(capacity < terminals)
                        //not then set it to false
                        possible = false;

                }

                if(possible == true)
                {

                    //if it is possible to accomodate request
                    for (DateTime x : mapLoaded.subMap(startx, endx).keySet()) {
                    {
                        //for dates n, update value for next operation
                        mapLoaded.put(x, mapLoaded.get(x) - terminals);
                    }
                }
                }else{
                 //nothing now
                }
        }else if(requestType.equals("Training")){
            //Training
             for (Integer capacity : mapLoaded.subMap(startx, endx).values()) {
                    //Provides an insight into capacity accomodation possibility
                    //testValue++;
                    terminals = 1;
                    if(capacity >= terminals)
                        possible = true;
                    else if(capacity < terminals)
                        possible = false;

                }


                if(possible == true)
                {
                    for (DateTime x : mapLoaded.subMap(startx, endx).keySet()) {
                    {
                        //46 so that all seats are reserved
                        mapLoaded.put(x, mapLoaded.get(x) - 46);

                    }
                }
                }else{
                 //nothing now
                }

        }


        return possible;
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:14:08+00:00Added an answer on May 27, 2026 at 1:14 pm

    If you have transient fields in Reservation that would explain it.

    But, I think that the problem is that you are actually displaying the dummy Reservation that you created at the start of retrieveReservation().

    Why? Because rset.next() is returning false.

    Why? Well take a look at this:

       PreparedStatement prepareStatement = con.prepareStatement("SELECT * FROM 
             SMD_RESERVATION_INSTANCES WHERE id = ?");         
       prepareStatement.setString(1, localIDTest);
       ResultSet rset = prepareStatement.executeQuery();
       prepareStatement.executeUpdate();
       //prepareStatement.close();
       con.commit();
    

    That’s pretty random. You don’t need to do both an executeQuery and an executeUpdate on the same prepared statement. And there’s no need to commit() at that point because this is a query!

    So, what I think is happening is that your spurious call to executeUpdate is closing the ResultSet so that when you call rset.next() it is returning false. (Another possible cause of rset.next() returning false would be if your earlier insert had failed / not committed.)

    Anyway, if rset.next() returns false, your code doesn’t even try to deserialize a retrieved object … and you end up returning the dummy object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application I use the ShinyBlue.xaml resource dictionary which has this code for
This code has an interesting bug: some_struct struct_array1[10] = {0}; some_struct struct_array2[10] = {0}
So this code has the off-by-one error: void foo (const char * str) {
I translated this code(it has bad side effect that it just capture the outer
I have this code that has one button that let's me choose an entry
bCrypt's javadoc has this code for how to encrypt a password: String pw_hash =
I was checking out this question which has this code - (NSArray *) percentagesRGBArray:(float[])
My code has something like this: HttpFileCollection files Instead of looping through each file
I have a friend who has code like this in his wordpress files: Blockquote
I am trying to execute a batch file using the Process class. This code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.