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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:57:16+00:00 2026-05-28T05:57:16+00:00

I am using Derby database with Java and Eclipse. I have a table which

  • 0

I am using Derby database with Java and Eclipse. I have a table which has a TIMESTAMP field and I use a model to populate a JTable from it. I am finding timestamp and data and java.sql and java.utils very confusing. The following line of code errors with cannot cast date to timestamp. mod is the model interfacing Derby table and JTable.

int rowcount = mod.getRowCount();
java.sql.Timestamp ts = (java.sql.Timestamp) mod.getValueAt(rowcount-1,1);

My objective is to get the date of the most recent record and subtract 30 days then run an sql query on the same database to find all the records more recent than that date. How do I recover the first timestamp, subtract the 30 days, then construct a query with the result of the subtraction as the condition in a WHERE clause. Sounds simple but I am having such difficulty that I feel I must be missing some fundamental principal. I thought conversion to long and back again might be the route but came up against the same cast problem.

  • 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-28T05:57:17+00:00Added an answer on May 28, 2026 at 5:57 am

    Timestamp is declared as

    public class Timestamp extends java.util.Date { ... }
    

    Therefore you can’t cast date to timstamp, you could create a timestamp from a date.

    Timstamp ts = new Timestamp( date.getTime() );
    

    To subtract 30 days this sequence might be helpful:

    Calendar cal = new GregorianCalendar();
    cal.setTime( date.getTime() );
    cal.add( Calendar.DAY_OF_MONTH, -30 );
    Date d30 = cal.getTime();
    

    Anyway I would try to perform this using only SQL.

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

Sidebar

Related Questions

I have a Java app that has an embedded Derby database (no hibernate though).
I have (java) code that creates and populates tables in a derby database, using
I have been developing a Java application using J2EE and a Derby database. My
I'm using Eclipse and wish to also use the Derby database and am having
I'm Using Camick's ListTableModel and RowTableModel from here http://tips4java.wordpress.com/2009/03/12/table-from-database/ However, the JTable is not
I am using Derby database. I wrote this query: InputStream is = new java.io.ByteArrayInputStream(BYTES);
I am developing an application using JSF in Eclipse IDE with Derby as database.
I have a custom UserType which stores a date/time value in a TIMESTAMP field
I need to enumerate the tables in a Derby (aka Java DB) database using
I am using Java Netbeans 6.9.1. I have an Table Called Workers in JavaDB.

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.