javabean的写法:
----------------------------------------------------
import com.sun.rowset.CachedRowSetImpl;
public CachedRowSetImpl get_rsfarm(String s_user)
{
try
{
Connection con = DriverManager.getConnection("proxool.Access");
Statement stmt = con.createStatement();
String strSQL = "select * from res_farm where username='" + s_user + "'";
ResultSet rs = stmt.executeQuery(strSQL);
CachedRowSetImpl crs = new CachedRowSetImpl();
crs.populate(rs);//这里拿走CachedRowSetImpl
rs.close();
stmt.close();
con.close();
return crs;
}
catch(Exception e)
{
CachedRowSetImpl crs=null;
return crs;
}
-------------------------------------------------------
jsp页面写法:
<jsp:useBean id="co" class="tc.consolebean" />
<jsp:useBean id="crs" class="com.sun.rowset.CachedRowSetImpl" />
<%
crs=co.get_rsfarm("123");
while(crs.next())
{
String s3 = crs.getString("type");out.println("类型:"+s3);out.println("<BR>");
String s4 = crs.getString("amount");out.println("数量:"+s4);out.println("<BR>");
String s5 = crs.getString("fx");out.println("数量:"+s5);out.println("<BR>");
}
crs.close();
%>
本文介绍了一种使用JavaBean结合CachedRowSetImpl从数据库获取并处理数据的方法。通过具体的代码示例展示了如何建立数据库连接、执行SQL查询并将结果集缓存到CachedRowSetImpl中,最后在JSP页面上展示数据。
326

被折叠的 条评论
为什么被折叠?



