Java日历将时间设置为SQL时间戳

时间:2019-05-14 14:15:59

标签: java mysql

能否请您告诉我这段代码为什么给出NullPointerException

PreparedStatement ps = con.prepareStatement("SELECT signupDate FROM users WHERE username=?");
ps.setString(1,username);
ResultSet rs = ps.executeQuery();
Calendar signUpMonth = Calendar.getInstance();
if(rs.next())
    signUpMonth.setTime(rs.getTimestamp(1));

`

 java.lang.NullPointerException
    at java.base/java.util.Calendar.setTime(Calendar.java:1800)
    at com.nane.validation.changePass(validation.java:80)
    at com.nane.loginServlet.doPost(loginServlet.java:25)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at     org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

`

0 个答案:

没有答案