java.sql.SQLException:无效的参数值:java.io.NotSerializableException [英] java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
本文介绍了java.sql.SQLException:无效的参数值:java.io.NotSerializableException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我遇到错误的SQL Connection类的代码.
This is my code of SQL Connection class where I am getting error.
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;
}
}
这里是LogAction
类,我在其中调用此getdata()
函数.
Here is the LogAction
class where i am calling this getdata()
function.
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;
}
将模型对象设置为准备好的语句的参数是没有道理的.
setting model object to the parameter of the prepared statement makes non sense.
这篇关于java.sql.SQLException:无效的参数值:java.io.NotSerializableException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文