gpt4 book ai didi

java.sql.SQLException : Invalid argument value: java. io.NotSerializableException 异常

转载 作者:行者123 更新时间:2023-11-30 23:16:56 40 4
gpt4 key购买 nike

这是我出现错误的 SQL 连接类代码。

public class SqlConnection {
static Connection con;
.......

static public ResultSet getData(String sql, List<LogModel> alist)
throws ClassNotFoundException, SQLException {
PreparedStatement pst = con.prepareStatement(sql);
if (alist != null) {
for (int i = 1; i <= alist.size(); i++) {
pst.setObject(i, alist.get(i-1)); //Exception at this Line
}
}
ResultSet rs = pst.executeQuery();
return rs;
}
}

这是我调用此 getdata() 函数的 LogAction 类。

public class LogAction extends ActionSupport implements ModelDriven<LogModel>, Preparable {

LogModel log = null;
List<LogModel> alist = null;
public static final String FAILURE = "failure";

@Override
public void prepare() throws Exception {
log = new LogModel();
alist = new ArrayList<LogModel>();
}

@Override
public LogModel getModel() {
return log;
}

public String login() throws ClassNotFoundException, SQLException {
String sql = "Select username,password from registration where username=? and password=?";
alist.add(log);
System.out.println(alist);
ResultSet rs = SqlConnection.getData(sql, alist);
if (rs.next()) {
return SUCCESS;
} else
return FAILURE;
}
}

最佳答案

将代码修改为

static public ResultSet getData(String sql, String username, String password)
throws ClassNotFoundException, SQLException {
PreparedStatement pst = con.prepareStatement(sql);
pst.setString(1, username);
pst.setString(2, password);
ResultSet rs = pst.executeQuery();
return rs;
}

将模型对象设置为准备好的语句的参数是没有意义的。

关于java.sql.SQLException : Invalid argument value: java. io.NotSerializableException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17212949/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com