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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:59:36+00:00 2026-06-03T19:59:36+00:00

I am querying a MySQL table and selecting varchar, Date, Time, Double, and Boolean

  • 0

I am querying a MySQL table and selecting varchar, Date, Time, Double, and Boolean data types. I take the data from the ResultSet and put it in a DefaultTableModel, which then gets put in a JTable, and then a JScrollPane for displaying.

All of the data is displayed correctly except the columns with java.sql.Time objects in them. These are being displayed as a date object, and they all have the value of Jan 1, 1970.

It seems that java.sql.Time objects are being read as java.sql.Date objects (I am guessing Jan 1, 1970 is being returned because the time value is outside of the range that would be valid for a date object).

I am confused because if I override the getColumnClass method in the DefaultTableModel to always return String.class and use the table method setAutoCreateRowSorter(true), when I click on the header of a column containing java.sql.Time objects to sort it, a java.lang.ClassCastException is thrown, and it says that java.sql.time can’t be cast as a String. Why does this correctly identify the data as java.sql.Time, but if I override the DefaultTableModel getColumnClass to return the correct class, it sees it as a date instead of a time? Any help resolving the issue would be greatly appreciated. Here is how I am overriding he getColumnClass method in the DefaultTableModel:

        model = new DefaultTableModel() {
            @Override
            public Class<?> getColumnClass(int columnIndex) {
                if (columnIndex == numberOfColumns) {
                    return Boolean.class;
                } else {
                    return getValueAt(1, columnIndex).getClass(); //return actual class
                    return String.class; //return string regardless of what class is
                }
            }
        };
  • 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-06-03T19:59:39+00:00Added an answer on June 3, 2026 at 7:59 pm

    The ClassCastException is coming because you are trying to cast the Time class as an String. It appears as an Date object because java.sql.Time and java.sql.Date are both subclasses of java.util.Date. These subclasses are just thin wrappers (Same thing with just enough extra information to be mapped in to SQL columns). So in a Swing JTable it’s being used as java.util.Date since java.sql types are irrelevant to swing components for the most part.

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

Sidebar

Related Questions

This is a follow up from my question: MySQL: Querying a table and possibly
I am querying a mySQL database to retrieve the data from 1 particular row.
Using MySQL and I have data being loaded into a table every second. I
If I am calling a list of links from a mysql table named categories
I'm new to database and querying in MySql. I have a table in my
I'm querying a mysql table which then loops through the results. One of the
I'm querying a bunch of cities from a zip-code table. I'd only like to
I have some php querying and printing the info of a mysql table on
Is there a way to query a MySQL table and get the last date
So. I have a table of data, in a MySQL database, eg: Artist Name

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.