JAVABEAN的疑问请大家看看!1!!!!!!
第一个代码;
主要是执行SQL语句取数据。
public class Lookup {
public Lookup(){}
public ArrayList gethash() throws SQLException{
ResultSet st = null;
Hashtable hs=new Hashtable();
ArrayList al=new ArrayList();
String goodsname[]=new String[20];
String unit[]=new String[10];
String introduction[]=new String[10];
String company[]=new String[10];
String price[]=new String[20];
String total[]=new String[10];
ConnectSql cql=new ConnectSql();
try{
String sql="select goodsname,introduction,unit,company,price,total from goods ";
st=cql.executeQuery(sql);
while(st.next()){
al.add(st.getString("goodsname"));
al.add(st.getString("unit"));
al.add(st.getString("introduction"));
al.add(st.getString("company"));
al.add(st.getString("price"));
al.add(st.getString("total"));
}
} catch(SQLException e){
System.out.println("the sql error:"+e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
return al;
}
}
这种是向页面返回结果集再 显示
根本没用到我的BEAN 啊
package Bean;
/**
* @author ms
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class GoodsBean{
String goodsname;
String introduction;
String unit;
String company;
float price;
int total;
public void setGoodsname(String goodsname){
this.goodsname=goodsname;
}
public String getGoodsname(){
return (this.goodsname);
}
public void setIntroduction(String introduction){
this.introduction=introduction;
}
public String getIntroduction(){
return (this.introduction);
}
public void setUnit(String unit){
this.unit=unit;
}
public String getUnit(){
return (this.unit);
}
public void setCompany(String company){
this.company=company;
}
public String getCompany(){
return (this.company);
}
public void setPrice(float price){
this.price=price;
}
public float getPrice(){
return (this.price);
}
public void setTotal(int total){
this.total=total;
}
public int getTotal(){
return (this.total);
}
}
请问我在执行SQL语句后该怎么做 是直接向BEAN里添加结果吗?
但是也是添加结果集啊
而且页面的SCOPE该设成什么才能直接调用JAVABEAN的GETXXX方法
请高手多多指点
问题点数:0、回复次数:7Top
1 楼panzhiwei(panzhiwei008)回复于 2004-09-03 17:57:49 得分 0
支持!Top
2 楼ybsoft(☆☆☆☆☆)回复于 2004-09-03 17:58:45 得分 0
SCOPE = REQUESTTop
3 楼freedom1980(力促)回复于 2004-09-03 18:25:10 得分 0
try{
String sql="select goodsname,introduction,unit,company,price,total from goods ";
st=cql.executeQuery(sql);
while(st.next()){
gb.setGoodsname(st.getString("goodsname"));
gb.setGoodsname(st.getString("unit"));
gb.setGoodsname(st.getString("introduction"));
gb.setGoodsname(st.getString("company"));
gb.setGoodsname(st.getString("price"));
gb.setGoodsname(st.getString("total"));
al.add(gb);
}
} catch(SQLException e){
System.out.println("the sql error:"+e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
return al;
}
}
页面SCOPE我用的是REQUEST啊
<% int i=0;
int a;
int j=0;
ArrayList al=new ArrayList();
al=lookup.gethash();
Object ia[]=al.toArray();
a=ia.length;
%>
function lookup(){
var index=<%=a%>;
var n=0;
document.write("<table width=500 height=500 border=1 align=center><tr>");
document.write("<th>商品名称</th><th>价格</th><th>计量单位</th><th>库存</th><th>产品介绍</th><th>生产厂家</th><tr>");
for(n=0;n<index;n++)
{
document.write("<td><%=gb.getGoodsname()%></td><td colspan=1><%=gb.getPrice()%></td><td><%=gb.getUnit()%></td><td><%=gb.getTotal()%></td><td colspan=1><%=gb.getIntroduction()%></td><td><%=gb.getCompany()%></td></table>");
}
return true;
}
但是显示的结果要摸是0要么是NULLTop
4 楼zheng2361yyyyyy(风云)回复于 2004-09-03 18:29:17 得分 0
你说的我看的不太明白,但是
java Bean 同时也是一个JAVA类 你可以像调用其它类一样调用呀
<%
ResultSet set=Bean.getResultSet();
%>Top
5 楼gameboy999(-'_'-)回复于 2004-09-03 18:31:58 得分 0
你从数据库中取数据怎么这么怪啊?Top
6 楼zhlmmc(zhlmmc)回复于 2004-09-03 18:37:36 得分 0
说实话,眼花Top
7 楼freedom1980(力促)回复于 2004-09-03 19:02:23 得分 0
<%
ResultSet set=Bean.getResultSet();
%>
你的意思是我的JAVA程序不用从后台返回结果集
直接用上面的语句就可以从BEAN里获取数据了
但是D:\tomcat4.1\work\Standalone\localhost\examples\lookgoods_jsp.java:79: cannot resolve symbol
symbol : method getResultSet ()
location: class Bean.GoodsBean
ResultSet st=gb.getResultSet();
Top




