日期:2014-05-17  浏览次数:20643 次

这个位置为什么会报错的呢?小问题,我是小鸟,请老鸟帮我看看
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
一个原因吧