当前位置: 代码迷 >> Java Web开发 >> 这个位置为什么会报错的呢?小疑点,小弟我是小鸟,请老鸟帮小弟我看看
  详细解决方案

这个位置为什么会报错的呢?小疑点,小弟我是小鸟,请老鸟帮小弟我看看

热度:6305   发布时间:2013-02-25 21:09:26
这个位置为什么会报错的呢?小问题,我是小鸟,请老鸟帮我看看
package com.bjsxt.shopping;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.bjsxt.shopping.util.DB;
import com.sun.jmx.snmp.Timestamp;


public class User {
private int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public Timestamp getRdate() {
return rdate;
}

public void setRdate(Timestamp rdate) {
this.rdate = rdate;
}
private String username;
private String password;
private String phone;
private String addr;
private Timestamp rdate;

public void save(){
Connection conn = DB.getConn();
String sql = "insert into user values (null,?,?,?,?,?)";
PreparedStatement pstmt = DB.getPStmt(conn,sql);
try {
pstmt.setString(1,username);
pstmt.setString(2, password);
pstmt.setString(3, phone);
pstmt.setString(4, addr);
pstmt.setTimestamp(5, new Timestamp(rdate.getDateTime()));
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}



}
}
红色部分就是报错的地方,错误提示:The method setTimestamp(int, Timestamp) in the type PreparedStatement is not applicable for the arguments (int, 
 Timestamp)

------解决方案--------------------------------------------------------
引入的类错了
应该是这个
java.sql
类 Timestamp
java.lang.Object
java.util.Date
java.sql.Timestamp
一个原因吧
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!