当前位置: 技术问答>高手请看,关于数据库插入的问题
iis7站长之家
问题2:插入一条记录,要它及时显示在JList中,我这样写为何不行,请大虾写处正确的
来源: 互联网 发布时间:2015-03-08
本文导语: void btnAdd_actionPerformed(ActionEvent evt) { //添加记录的方法与响应btnAdd的方法 String sql=""; sql="insert into weiming.酒钢商业用房基本资料库(街区,栋号,房号,小区,租金标准,建筑面积,使用面积,...
void btnAdd_actionPerformed(ActionEvent evt)
{
//添加记录的方法与响应btnAdd的方法
String sql="";
sql="insert into weiming.酒钢商业用房基本资料库(街区,栋号,房号,小区,租金标准,建筑面积,使用面积,房屋状况,使用状态,煤气,有无煤气IC表,用电,有无电IC表,自来水,有无水IC表,暖气,下水道,卫生间,住宅编号) values(";
sql=sql + "'" + (String)comjiequ.getSelectedItem() + "',";
sql=sql + "'" + (String)comdonghao.getSelectedItem() + "',";
sql=sql + "'" + txtfanghao.getText() + "',";
sql=sql + "'" + (String)comxiaoqu.getSelectedItem() + "',";
sql=sql + "'" + txtzjbz.getText() + "',";
sql=sql + "'" + txtjzmj.getText() + "',";
sql=sql + "'" + txtsymj.getText() + "',";
sql=sql + "'" + (String)comfwzk.getSelectedItem() + "',";
sql=sql + "'" + (String)comsyzt.getSelectedItem() + "',";
String meiqiValue=cbxmeiqi.isSelected()? "有" : "没有";
String zlsValue=cbxzls.isSelected()? "有" : "没有";
String meibiaoValue=cbxmeibiao.isSelected()? "有" : "没有";
String dianValue=cbxdian.isSelected()? "有" : "没有";
String dianbiaoValue=cbxdianbiao.isSelected()? "有" : "没有";
String nuanqiValue=cbxnuanqi.isSelected()? "有" : "没有";
String shuibiaoValue=cbxshuibiao.isSelected()? "有" : "没有";
String wsjValue=cbxwsj.isSelected()? "有" : "没有";
String xsdValue=cbxxsd.isSelected()? "有" : "没有";
sql=sql + "'" + meiqiValue + "',";
sql=sql + "'" + meibiaoValue + "',";
sql=sql + "'" + dianValue + "',";
sql=sql + "'" + dianbiaoValue + "',";
sql=sql + "'" + zlsValue + "',";
sql=sql + "'" + shuibiaoValue + "',";
sql=sql + "'" + nuanqiValue + "',";
sql=sql + "'" + xsdValue + "',";
sql=sql + "'" + wsjValue + "',";
sql=sql + "商业房.nextval" + ")";
try
{
db_jiequ.execUpdate(sql);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
Vector vec=new Vector();
String itemList5="";
String itemList3="";
String itemList2="";
String itemList="";
lstylrfwzl.removeAll();
try{
ResultSet yiluru=db_jiequ.rs_jiequ("SELECT * FROM WEIMING.酒钢商业用房基本资料库 order by 街区,栋号,房号");
while (yiluru.next())
{
itemList2=yiluru.getString(2);
itemList3=yiluru.getString(3);
itemList5=yiluru.getString(5);
itemList=itemList5 + itemList3 + "栋" + itemList2 +"号";
vec.addElement(itemList);
}
lstylrfwzl=new JList(vec);
lstylrfwzl.repaint();
}
catch(Exception e)
{
System.out.println(itemList);
}
}
要怎样才能刷新lstylrfwzl呢?
{
//添加记录的方法与响应btnAdd的方法
String sql="";
sql="insert into weiming.酒钢商业用房基本资料库(街区,栋号,房号,小区,租金标准,建筑面积,使用面积,房屋状况,使用状态,煤气,有无煤气IC表,用电,有无电IC表,自来水,有无水IC表,暖气,下水道,卫生间,住宅编号) values(";
sql=sql + "'" + (String)comjiequ.getSelectedItem() + "',";
sql=sql + "'" + (String)comdonghao.getSelectedItem() + "',";
sql=sql + "'" + txtfanghao.getText() + "',";
sql=sql + "'" + (String)comxiaoqu.getSelectedItem() + "',";
sql=sql + "'" + txtzjbz.getText() + "',";
sql=sql + "'" + txtjzmj.getText() + "',";
sql=sql + "'" + txtsymj.getText() + "',";
sql=sql + "'" + (String)comfwzk.getSelectedItem() + "',";
sql=sql + "'" + (String)comsyzt.getSelectedItem() + "',";
String meiqiValue=cbxmeiqi.isSelected()? "有" : "没有";
String zlsValue=cbxzls.isSelected()? "有" : "没有";
String meibiaoValue=cbxmeibiao.isSelected()? "有" : "没有";
String dianValue=cbxdian.isSelected()? "有" : "没有";
String dianbiaoValue=cbxdianbiao.isSelected()? "有" : "没有";
String nuanqiValue=cbxnuanqi.isSelected()? "有" : "没有";
String shuibiaoValue=cbxshuibiao.isSelected()? "有" : "没有";
String wsjValue=cbxwsj.isSelected()? "有" : "没有";
String xsdValue=cbxxsd.isSelected()? "有" : "没有";
sql=sql + "'" + meiqiValue + "',";
sql=sql + "'" + meibiaoValue + "',";
sql=sql + "'" + dianValue + "',";
sql=sql + "'" + dianbiaoValue + "',";
sql=sql + "'" + zlsValue + "',";
sql=sql + "'" + shuibiaoValue + "',";
sql=sql + "'" + nuanqiValue + "',";
sql=sql + "'" + xsdValue + "',";
sql=sql + "'" + wsjValue + "',";
sql=sql + "商业房.nextval" + ")";
try
{
db_jiequ.execUpdate(sql);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
Vector vec=new Vector();
String itemList5="";
String itemList3="";
String itemList2="";
String itemList="";
lstylrfwzl.removeAll();
try{
ResultSet yiluru=db_jiequ.rs_jiequ("SELECT * FROM WEIMING.酒钢商业用房基本资料库 order by 街区,栋号,房号");
while (yiluru.next())
{
itemList2=yiluru.getString(2);
itemList3=yiluru.getString(3);
itemList5=yiluru.getString(5);
itemList=itemList5 + itemList3 + "栋" + itemList2 +"号";
vec.addElement(itemList);
}
lstylrfwzl=new JList(vec);
lstylrfwzl.repaint();
}
catch(Exception e)
{
System.out.println(itemList);
}
}
要怎样才能刷新lstylrfwzl呢?
|
//
lstylrfwzl = new JList(vec);以后只是让lstylrfwzl重新指向内存中刚new出来还没显示的JList对象而已;
lstylrfwzl = new JList(vec);以后只是让lstylrfwzl重新指向内存中刚new出来还没显示的JList对象而已;