读书人

JSP中调用的一个查询方法不知道哪儿

发布时间: 2011-11-20 23:14:11 作者: rapoo

JSP中调用的一个查询方法,不知道哪里有错,帮忙看看啊
public IClr findByLsh(String lsh) throws SysException
{
//在findByLsh中
Connection conn = null;
DBConnection db = new DBConnection("ce.dbcon.dbConfig");
PreparedStatement pstmt = null;

IClr clr = null;

try
{
conn = db.getConnection("ce.dbcon.dbConfig");
if(conn != null)
{
String sql = "select * from PUBLIC_CLR_TB where lsh=? and id=(select max(id) from PUBLIC_CLR_TB where lsh=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(3, lsh);//对应问号位置参数的
ResultSet rs = pstmt.executeQuery();

while(rs.next())
{
clr = new ClrBean();
clr.setGh(rs.getString(2));
clr.setLsh(rs.getString(3));
}
rs.close();
}
} catch (SQLException e)
{
e.getMessage();
throw new SysException(e.getMessage());
}finally{
if(pstmt != null)
try
{
pstmt.close();
} catch (SQLException e)
{
e.getMessage();
}
db.closeConnection();
}
//退出findByLsh方法
return clr;
}

[解决办法]
String sql = "select * from PUBLIC_CLR_TB where lsh=? and id=(select max(id) from PUBLIC_CLR_TB where lsh=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(3, lsh);//对应问号位置参数的

两个问号3哪来的
[解决办法]
Invalid parameter binding(s).
无效的参数帮顶。

[解决办法]
String sql = "select * from PUBLIC_CLR_TB where lsh=? and id=(select max(id) from PUBLIC_CLR_TB where lsh=?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(3, lsh);//对应问号位置参数的
ResultSet rs = pstmt.executeQuery();

sql中的的"?"和pstmt.setString(index,lsh);中的index对应
从1开始

读书人网 >Java Web开发

热点推荐