我没做过试验,只是在网上看过此文章,所以请教大家,用此方法有什么好处? CachedRowSet是否也存内存里? 在API里有这么段话: In summary, a CachedRowSet object can be thought of as simply a disconnected set of rows that are being cached outside of a data source. Being thin and serializable, it can easily be sent across a wire, and it is well suited to sending data to a thin client. However, a CachedRowSet object does have limitations: Because it stores its data in memory, it is not suitable for extremely large data sets.
public Collection getCars(String make,String model,double highprice) { List cars=new ArrayList(); Connection conn=null; Statement st=null; ResultSet rs=null; try { conn=dataSource.getConnection(); st=conn.createStatement(); rs=st.executeQuery("select ake,model,year,color,mileage,"+ "price,vin from "+tableName+" where price<="+highPrice+" and "+ "model='"+model+"' and make='"+mak+"'"); while(rs.next()) { int year=rs.getInt(3); String color=rs.getString(4); int mileage=rs.getInt(5); double price-rs.getDouble(6); int vin=rs.getInt(7); cars.add(new CarValueObject(make,model,year,color,mileage, price,vin)); } return cars; } catch(SQLException e) { e.printStarcTrace(); } finally { if(rs!=null) try(rs.close();} catch(Exception ignore){} if(st!=null) try(st.close();} catch(Exception ignore){} if(conn!=null) try(conn.close();} catch(Exception ignore){} } }
CachedRowSet是否也存内存里?
在API里有这么段话:
In summary, a CachedRowSet object can be thought of as simply a disconnected set of rows that are being cached outside of a data source. Being thin and serializable, it can easily be sent across a wire, and it is well suited to sending data to a thin client. However, a CachedRowSet object does have limitations: Because it stores its data in memory, it is not suitable for extremely large data sets.
{
List cars=new ArrayList();
Connection conn=null;
Statement st=null;
ResultSet rs=null;
try
{
conn=dataSource.getConnection();
st=conn.createStatement();
rs=st.executeQuery("select ake,model,year,color,mileage,"+
"price,vin from "+tableName+" where price<="+highPrice+" and "+
"model='"+model+"' and make='"+mak+"'");
while(rs.next())
{
int year=rs.getInt(3);
String color=rs.getString(4);
int mileage=rs.getInt(5);
double price-rs.getDouble(6);
int vin=rs.getInt(7);
cars.add(new CarValueObject(make,model,year,color,mileage,
price,vin));
}
return cars;
}
catch(SQLException e)
{
e.printStarcTrace();
}
finally
{
if(rs!=null) try(rs.close();} catch(Exception ignore){}
if(st!=null) try(st.close();} catch(Exception ignore){}
if(conn!=null) try(conn.close();} catch(Exception ignore){}
}
}
CachedRowset的方法我很早就用过,因为它提供离线的结果及缓存,比较方便!对EJB来说,容易序列化!但它的缺电就是在客户端(或前端),一般是Jsp,Servlet不能显式表现返回内容。编程不方便!
而采用定义对象,加入到数组的方法就可以避免这个问题!目前我在EJB开发中主要是采用这种方法!
这就是value object方式吗?请教了。
我是用struts1.1+ejb+weblogic7+jbuilder7开发,框架正建中,头痛中呀,请教了
我以前用dto,现在用vo.