0

I have a timestamp column in a mysql table. I am unable to retrieve this value from java.sql.ResultSet using getTimestamp(String label).

ResultSet rs = preparedStatement.getResultSet();
        rList = new ArrayList<String>();
        while (rs.next() != false){
            rList.add(rs.getString("urlstring"));
            if (rs.getTimestamp("mytimestamp") == null) {
                rList.add("null");
            } else {
                rList.add(rs.getTimestamp("mytimestamp").toString());
            }
        }

I can confirm that there are results in the resultset. When I omit the statements which attempt to retrieve the timestamp from the resultset, the list populates as expected, however, when I run the above code, there is no error but the list is empty.

1
  • rather than getting the value by name, maybe try by index. Have you run this through a debugger? Commented May 24, 2013 at 8:09

2 Answers 2

1

getTimestamp() works on DateTime MySQL columns.

See Handling MySQL datetimes and timestamps in Java in order to resolve your question :)

Sign up to request clarification or add additional context in comments.

Comments

0

Did you do

ResultSet rs = preparedStatement.exequteQuery();

You could try (if this were the first while (rs.next())).

if (rs.first()) {
    do {
        rList.add(rs.getString("urlstring"));
        if (rs.getTimestamp("mytimestamp") == null) {
            rList.add("null");
        } else {
            rList.add(rs.getTimestamp("mytimestamp").toString());
        }
    } while (rs.next());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.