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

求大神,帮忙看看小弟代码到底哪里错了?
<%
String strId = request.getParameter("id");
int p_id = Integer.parseInt(strId);
%>
<%!
private void tree(List<Neirong> neirong, Connection conn, int id){
String sql = "select * from neirong where pid = " +p_id ;
Statement stmt = DB.createStmt(conn);
ResultSet rs = DB.executeQuery(stmt, sql);
try {
while(rs.next()){
Neirong n = new Neirong();
n.setPid(rs.getInt("pid"));
n.setN_author(rs.getString("n_author"));
n.setN_neirong(rs.getString("n_neirong"));
n.setN_date(rs.getDate("n_date"));
neirong.add(n);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
%>

<%
List<Neirong> neirong = new ArrayList<Neirong>();
Connection conn = DB.getConn();
tree(neirong, conn, 0);
DB.close(conn);
%>
总是显示我sql语句中的p_id cannot be resolved to a variable
我确实在前一个页面传过来id了
------解决方案--------------------
引用:
有人吗?小弟很捉急啊,最近毕设做得好烦呐

<%!
int p_id;
%>

<%
String strId = request.getParameter("id");
p_id = Integer.parseInt(strId);
%>