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 6713343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:22:08+00:00 2026-05-26T08:22:08+00:00

I am working on an application where i need to store an object of

  • 0

I am working on an application where i need to store an object of a custom class into a database and be able to retrieve the object and use it at a later time.

The custom class is called Quiz and the database is mySQL and i am using a blob to store the object.

I am able to store the object, but when i try to retrieve the object for use, i am getting the following error. Yes, i have googled. I have found some similar problems and tried their solutions to no avail. Please view the code excerpts below and let me know if you need any more information.

Thank you!

//Storing the Quiz object

public static void setQuizObject(String classId, Object quiz, int quizEnabled) {
    try {
        if (connect.isValid(0)) {
            statement = connect.createStatement();
            statement.executeUpdate("insert into " + 
                    DBHelper.MJLADB_QUIZTABLE + "(" + 
                    DBHelper.MJLADB_QUIZTABLE_CLASSID + ", " + 
                    DBHelper.MJLADB_QUIZTABLE_QUIZOBJECT + ", " + 
                    DBHelper.MJLADB_QUIZTABLE_QUIZENABLED + ") values ('" + 
                    classId + "', '" + 
                    quiz + "', '" + 
                    quizEnabled + "')");
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

//Getting the quiz object (handling the conversion from resultset to an arraylist)

    public static ArrayList<Object[]> resultSetToTableModel(ResultSet row) throws SQLException {

        ArrayList<Object[]> classList = new ArrayList<Object[]>();
        ResultSetMetaData meta = row.getMetaData();

        Object cols[] = new Object[meta.getColumnCount()];
        for (int i = 0; i < cols.length; i++) {
            cols[i] = meta.getColumnLabel(i + 1);
        }
        classList.add(cols);

        while (row.next()) {
            Object data[] = new Object[cols.length];
            int quizColumn = -1;
            try {
                quizColumn = row.findColumn(DBHelper.MJLADB_QUIZTABLE_QUIZOBJECT_A);
            }
            catch (SQLException e) {
                quizColumn = -1;
            }

            for (int i = 0; i < data.length; i++) {
//              if (row.getInt(DBHelper.MJLADB_QUIZTABLE_QUIZOBJECT_A) == (i + 1)) {
                Object x;
                Quiz quiz;
                if (quizColumn == (i + 1)) {
                    InputStream is = row.getBlob(i + 1).getBinaryStream();
                    try {
                        ObjectInputStream ois = new ObjectInputStream(is);
                        x = ois.readObject();
                        quiz = (Quiz)x;
                        data[i] = quiz;
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }
                else {
                    data[i] = row.getObject(i + 1); 
                }
            }
//original stuff
//          Object data[] = new Object[cols.length];
//          for (int i = 0; i < data.length; i++) {
//              data[i] = row.getObject(i + 1);
//          }
            classList.add(data);
        }

        return classList;
    }

//The problem:

java.io.StreamCorruptedException: invalid stream header: 626F6775
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at school.cs321.mjla.util.DBHelper.resultSetToTableModel(DBHelper.java:533)
    at school.cs321.mjla.util.DBHelper.getTQuizList(DBHelper.java:445)
    at school.cs321.mjla.controlpanel.ControlPanelModel.<init>(ControlPanelModel.java:46)
    at school.cs321.mjla.mediator.Mediator.startControlPanel(Mediator.java:97)
    at school.cs321.mjla.mainview.MainViewController.controlPanelbutton(MainViewController.java:55)
    at school.cs321.mjla.mainview.MainView$6.actionPerformed(MainView.java:169)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
  • 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-26T08:22:09+00:00Added an answer on May 26, 2026 at 8:22 am

    I figured it out. I had forgot to serialize my object… OOPS!

    Here is the final code once it was working:

    public static ArrayList<Object[]> resultSetToTableModel(ResultSet row) throws SQLException {
    
            ArrayList<Object[]> classList = new ArrayList<Object[]>();
            ResultSetMetaData meta = row.getMetaData();
    
            Object cols[] = new Object[meta.getColumnCount()];
            for (int i = 0; i < cols.length; i++) {
                cols[i] = meta.getColumnLabel(i + 1);
            }
            classList.add(cols);
    
            while (row.next()) {
                Object data[] = new Object[cols.length];
                int quizColumn = -1;
                try {
                    quizColumn = row.findColumn(DBHelper.MJLADB_QUIZTABLE_QUIZOBJECT_A);
                    if (quizColumn > 0) {
                        System.out.println("greater than 0");
                    }
                }
                catch (SQLException e) {
                    quizColumn = -1;
                }
    
                for (int i = 0; i < data.length; i++) {
                    if (quizColumn == (i + 1)) {
                        byte[] buf = row.getBytes(i + 1);
                        ObjectInputStream objectIn = null;
                        if (buf != null) {
                            try {
                                objectIn = new ObjectInputStream(new ByteArrayInputStream(buf));
                                data[i] = objectIn.readObject();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (ClassNotFoundException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
    
                        }
    
                    }
                    else {
                        data[i] = row.getObject(i + 1); 
                    }
                }
                classList.add(data);
            }
    
            return classList;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need JavaScript working almost perfectly in my application that should be able to
I need to be able to save and load images into an SQLite database
I'm working on an application and I need to store the users password, so
I am working on an application where i need to transfer mails from a
I'm working on an application where I need to generate unique, non-sequential IDs. One
I am working on an application where I need to integrate the search engine.
I'm working on a web-application and need to figure out the best way to
I'm working in a .net application where we need to generate XML files on
I am working on an ASP.NET MVC application where I need to export data
We've been working on web application where in we need to implement traditional web-apps

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.