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

  • Home
  • SEARCH
  • 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 7719251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:22:08+00:00 2026-06-01T03:22:08+00:00

The weird behavior is that a java.sql.Timestamp that I create using the System.currentTimeMillis() method,

  • 0

The weird behavior is that a java.sql.Timestamp that I create using the System.currentTimeMillis() method, is stored in my MySQL database as 1970-01-01 01:00:00.

The two timestamps I am creating are to mark the beginning and end of a monitoring task I am trying to perform, what follows are excepts from the code where the behavior occurs

final long startTime = System.currentTimeMillis();
while(numberOfTimeStepsPassed < numTimeStep) {
/*
* Code in here 
*/
}
final long endTime = System.currentTimeMillis();
return mysqlConnection.insertDataInformation(matrixOfRawData, name,Long.toString(startTime), 
                                                 Long.toString(endTime), Integer.toString(numTimeStep),
                                                 Integer.toString(matrixOfRawData[0].length), owner,
                                                 type);

And here is the code used for inserting the time stamps and other data into the MySQL database

public String insertDataInformation(final  double [][] matrix,
                                    final String ... params) {
    getConnection(lookUpName);
    String id = "";
    PreparedStatement dataInformationInsert = null;
    try {
        dataInformationInsert =
                databaseConnection.prepareStatement(DATA_INFORMATION_PREPARED_STATEMENT);
        id = DatabaseUtils.createUniqueId();
        int stepsMonitored = Integer.parseInt(params[STEPS_MONITORED]);
        int numberOfMarkets = Integer.parseInt(params[NUMBER_OF_MARKETS]);
        dataInformationInsert.setNString(ID_INDEX, id);
        dataInformationInsert.setNString(NAME_INDEX, params[0]);
        dataInformationInsert.setTimestamp(START_INDEX, new Timestamp(Long.parseLong(params[START_INDEX])));
        dataInformationInsert.setTimestamp(END_INDEX, new Timestamp(Long.parseLong(params[END_INDEX])));
        dataInformationInsert.setInt(STEPS_INDEX, stepsMonitored);
        dataInformationInsert.setInt(MARKETS_INDEX, numberOfMarkets);
        dataInformationInsert.setNString(OWNER_INDEX, params[OWNER]);
        dataInformationInsert.setNString(TYPE_INDEX, params[TYPE]);
        dataInformationInsert.executeUpdate();
        insertRawMatrix(matrix, id, Integer.toString(stepsMonitored), Integer.toString(numberOfMarkets));
    } catch (SQLException sqple) {
        // TODO Auto-generated catch block
        sqple.printStackTrace();
        System.out.println(sqple.getSQLState());
    } finally {
        close(dataInformationInsert);
        dataInformationInsert = null;
        close(databaseConnection);
    }
    return id;
}

The important lines of code are :

dataInformationInsert.setTimestamp(START_INDEX, new Timestamp(Long.parseLong(params[START_INDEX])));
dataInformationInsert.setTimestamp(END_INDEX, new Timestamp(Long.parseLong(params[END_INDEX])));

The JavaDocs on the TimeStamp ( http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/Timestamp.html ) says that it takes in time in milliseconds since 1st January 1970 and a simple print test confirms this.

What I am looking for is:

  • A reason for this behavior when trying to store timestamps in a MySQL database through java.sql.Timestamp?
  • Any solutions to this behavior?
  • Any possible alternatives?
  • Any possible improvements?

EDIT:
Been asked to include what START_INDEX and END_INDEX are:

 private static final int END_INDEX = 4;
 private static final int START_INDEX = 3;

Apologises for not putting them in the original post.

  • 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-01T03:22:11+00:00Added an answer on June 1, 2026 at 3:22 am

    Okay, look at your call:

    insertDataInformation(matrixOfRawData, name, Long.toString(startTime), 
                          Long.toString(endTime), Integer.toString(numTimeStep),
                          Integer.toString(matrixOfRawData[0].length), owner,
                          type);
    

    So params will have values:

    0: name
    1: start time
    2: end time
    3: numTimeStep
    4: matrixOfRowData[0].length
    5: owner
    6: type
    

    Then you’re doing:

    dataInformationInsert.setTimestamp(START_INDEX,
        new Timestamp(Long.parseLong(params[START_INDEX])));
    

    … where START_INDEX is 3.

    So you’re using the value corresponding to numTimeStep as the value for the timestamp… I suspect you don’t want to do that.

    I would strongly advise you to create a simple object type (possibly a nested type in the same class) to let you pass these parameters in a strongly typed, simple to get right fashion. The string conversion and the access by index are both unwarranted, and can easily give rise to errors.

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

Sidebar

Related Questions

I was working on HTTP post using java and encountered a weird stream behavior.
I am getting a weird behavior. I have a class that I created that
I am developing a Java web application that bases it behavior through large XML
Here is a weird behavior that I don't understand about custom views. I have
It seems that i have this weird behavior in my Web Client My application
I'm experiencing really weird behavior with the Socket.Connect method in C#. I am attempting
We are getting a very weird behavior in our development environment that is consistent
I have some extremely weird behavior that seems to result in silent exceptions. How
i recently stumbled upon a seemingly weird behavior that Google completely failed to explain.
Weird behavior when mixing loading of assemblies using Assembly.LoadFrom and Assembly.Load : I have

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.