高手看看吧!!!
告白气球 2012-03-30 04:53:44 <c:forEach var="mtvlist" items="${sessionScope.mtvlist}">
<form method="post" name="form1" id="form1" action="MtvServlet?action=SeachMtv&mtvname=${mtvlist.mtvname}">
</c:forEach>
请问我这样可以传参过去吧?我在做模糊查询和分页,为什么我的sql语句在数据库可以查询出,在控制台count输出的是0呢?下面是我的count方法。高手看看吧。
public int MtvNameCount(String mtvname)
{
int count = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
dbconn = new VideoDBConn();
conn = dbconn.getDataSource().getConnection();
String sql = "";
if(mtvname==null)
{
sql = "select count(*) as t from mtv ";
pstmt = conn.prepareStatement(sql);
}
else
{
sql="select count(*) as t from mtv where mtvname =?";
System.out.println(sql);
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, mtvname);
}
rs = pstmt.executeQuery();
while(rs.next())
{
count = rs.getInt("t");
System.out.println(count);
}
}
catch(Exception e)
{
logger.error("MtvCount()方法出错:"+e.getMessage());
e.printStackTrace();
}
finally
{
dbconn.closeResultSet(rs);
dbconn.closePreparedStatement(pstmt);
dbconn.closeConnection(conn);
}
return count;
}