0
 String content = "SELECT * FROM " + "floor" + floor + " WHERE Roomnumber ='" + roomresult + "'";
                System.out.println("next query->" + content);
                statement.execute(content);
                ResultSet rs = statement.getResultSet();

Date u = rs.getDate("CheckIn");

I want to transform the java.sql.date into java.util.date. I think the final sentence is correct , but the java told me that there is a NullPointerExceptio

6
  • 2
    PLEASE read this: SQL Injection and How to Prevent It?. What you're doing is extremely unsafe and is a security flaw in your application. Commented May 11, 2020 at 9:49
  • 1
    also you probably wanted to use statement.executeQuery(content), else you won't have a result Commented May 11, 2020 at 9:51
  • 2
    You shouldn't be using java.util.Date anyway. Even if you had to load a java.sql.Date from the database, it's best to convert it to the appropriate class from java.time. It's also possible to get the value as the appropriate type using getObject in most modern JDBC drivers. Commented May 11, 2020 at 9:56
  • So what is the exactly data type i should use to represent the data from database Commented May 11, 2020 at 10:15
  • You can take the reference from here : stackoverflow.com/questions/22784523/… Commented May 11, 2020 at 10:17

1 Answer 1

-2

if u want convert java.sql.date to java.util.date, use :

new java.util.Date(rs.getDate("CheckIn").getTime())

NullPointerException , may be CheckIn cloum not exist, or it be null;

pleas make sure CehckIn field exist and is not be null;

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

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.