我正在尝试运行查询,但每当我运行时,我都会收到一条错误消息,提示“列地址不能为空”。
这是我的代码。
package com.rajesh.action;
import java.sql.*;
public class AccountDao {
public static int save(Actionraju r){
int status =0;
Connection con=GetCon.getCon();
PreparedStatement ps;
try {
ps = con.prepareStatement("Insert into account (accountno, username, password, repassword, amount, address, phone) values (?,?,?,?,?,?,?)");
ps.setInt(1,r.getAccountno());
ps.setString(2,r.getUsername());
ps.setString(3,r.getPassword());
ps.setString(4,r.getRepassword());
ps.setDouble(5,r.getAmount());
ps.setString(6,r.getAddress1());
ps.setDouble(7,r.getPhone());
status=ps.executeUpdate();
}
catch(Exception e){
e.printStackTrace();}
return status;
}
}
我的 Actionraju.java 看起来像这样。
package com.rajesh.action;
public class Actionraju {
private int accountno;
private String username;
private String password;
private String repassword;
private Double amount;
private String address;
private Double phone;
public int getAccountno() {
return accountno;
}
public void setAccountno(int accountno) {
this.accountno = accountno;
}
public Double getAmount() {
return amount;
}
public void setAmount(Double amount) {
this.amount = amount;
}
public Double getPhone() {
return phone;
}
public void setPhone(Double phone) {
this.phone = phone;
}
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 getRepassword() {
return repassword;
}
public void setRepassword(String repassword) {
this.repassword = repassword;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String execute(){
int i = AccountDao.save(this);
if(i>0){
return "success";
}
return "error";
}
}
在我的 mysql 数据库中,我有 7 列,即“accountno”、“username”、“password”、repassword”、“amount”、“address”、“phone”。对于所有这 7 列,我选中了“not null”框和这里我的“accountno”是主键。
请任何人帮我解决这个问题。我是新手。