Topic: 求助!总是报 无效游标...的错误 |
Print this page |
1.求助!总是报 无效游标...的错误 | Copy to clipboard |
Posted by: soso2999 Posted on: 2005-11-07 00:32 请大家帮帮忙,看一程序是什么问题啊?总是报无效游标,表格2不能显示,而且表格1的标题为什么不能显示出来呢?好象还存在其他的问题,请帮帮忙,拜托了!! 谢谢了!! import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.sql.*; import java.util.*; public class vipqueryFrame extends JInternalFrame implements ActionListener { JComboBox jcb; JTextField jtf; JButton jb1,jb2; String conStr="VIP号"; Connection connect; Statement stmt; ResultSet rs,prs; JPanel jp,jp1,jp2; JTable jj,jtaa; public vipqueryFrame() { super("VIP信息查询窗口",true,true,true,true); this.setSize(new Dimension(440,240)); this.setVisible(true); this.setLayout(new BorderLayout()); jp=new JPanel(new GridLayout(2,1)); jp1=new JPanel(new GridLayout(1,5)); JLabel jlabel=new JLabel("查询条件"); String condition[]={"VIP号","会员名称"}; jcb=new JComboBox(condition); jtf=new JTextField(10); jb1=new JButton("查询"); jb1.addActionListener(this); jb2=new JButton("返回"); jb2.addActionListener(this); jp1.add(jlabel); jp1.add(jcb); jp1.add(jtf); jp1.add(jb1); jp1.add(jb2); jp.add(jp1); //默认表格1 jp2=new JPanel(new GridLayout(1,1)); JTable j=new JTable(); jp2.add(j); jp.add(jp2); //默认表格2 JTable jta=new JTable(); JScrollPane pscroll=new JScrollPane(jta); JScrollBar pBar=pscroll.getVerticalScrollBar(); pBar.setValue(pBar.getMaximum()); this.getContentPane().add(jp,BorderLayout.NORTH); this.getContentPane().add(pscroll,BorderLayout.CENTER); } public void actionPerformed(ActionEvent e) { String query1=""; String query2=""; int id=0; String name; //查询条件的处理 if(e.getSource().equals(jcb)) { conStr=jtf.getText().toString(); } if(conStr.equals("VIP号")&&!jtf.getText().equals("")) { try { id=Integer.parseInt(jtf.getText().toString()); query1="select * from vipID where vip_id ="+id+""; query2="select vip_id as 'VIP号',v_name as '会员姓名',p_id as '商品编号',p_name as '商品名称',p_price as '商品价格',money as '实收金额' from consume where vip_id="+id+""; } catch (Exception ex) { JOptionPane.showMessageDialog(this,"条件错误!"); return; } } else { name=new String(jtf.getText().toString()); query1="select vip_id as 'VIP号',v_time as '入会时间',v_name as '会员名称',v_age as '会员年龄',v_type as '会员类型' from vipID where v_name ='"+name+"'"; query2="select vip_id as 'VIP号',v_name as '会员姓名',p_id as '商品编号',p_name as '商品名称',p_price as '商品价格',money as '实收金额' from consume where v_name='"+name+"'"; } if(jtf.getText().equals("")) { query1="select vip_id as 'VIP号',v_time as '入会时间',v_name as '会员名称',v_age as '会员年龄',v_type as '会员类型' from vipID"; query2="select vip_id as 'VIP号',v_name as '会员姓名',p_id as '商品编号',p_name as '商品名称',p_price as '商品价格',money as '实收金额' from consume"; } //默认表格 //..... //查询并显示结果 if(e.getSource().equals(jb1)) { JOptionPane.showMessageDialog(this,id); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); connect=DriverManager.getConnection("jdbc:odbc:VIP"); stmt=connect.createStatement(); rs=stmt.executeQuery(query1); boolean rsok=rs.next(); if(!rsok) { JOptionPane.showMessageDialog(this,"此VIP不存在"); return; } //处理表1信息 Vector vcol=new Vector(); Vector vrow=new Vector(); Vector pcol=new Vector(); Vector prow=new Vector(); try { ///表1的标题 ResultSetMetaData rsmd=rs.getMetaData(); for(int i=1;i<=rsmd.getColumnCount();i++) { vcol.addElement(rsmd.getColumnName( i ) ); } //表1的内容 do { Vector row=new Vector(); for(int ii=1;ii<=rsmd.getColumnCount();ii++) { row.addElement(rs.getString(ii)); } vrow.addElement(row); }while(rs.next()); //表1 jj=new JTable(vrow,vcol); jp2.add(jj); jp.add(jp1); jp2.remove(0); jp.add(jp2); jp.validate(); this.getContentPane().add(jp,BorderLayout.NORTH); this.getContentPane().validate(); //表2的标题 prs=stmt.executeQuery(query2); prs.next(); ResultSetMetaData prsmd=prs.getMetaData(); for(int n=1;n<=prsmd.getColumnCount();n++) { pcol.addElement(prsmd.getColumnName( n )); } //表2的内容 do { Vector rowp=new Vector(); for(int nn=1;nn<=prsmd.getColumnCount();nn++) { rowp.addElement(prs.getString(nn)); } prow.addElement(rowp); }while(prs.next()); //表2 jtaa=new JTable(prow,pcol); JScrollPane pscrollpane=new JScrollPane(jtaa); this.getContentPane().remove(1); JScrollBar pBar=pscrollpane.getVerticalScrollBar(); pBar.setValue(pBar.getMaximum()); this.getContentPane().add(pscrollpane,BorderLayout.CENTER); this.getContentPane().validate(); } catch (Exception ex) { ex.printStackTrace(); } } catch (Exception ex) { ex.printStackTrace(); } } } } |
2.Re:求助!总是报 无效游标...的错误 [Re: soso2999] | Copy to clipboard |
Posted by: hualee Posted on: 2005-11-07 19:44 和我上次出的错误一样,期待高手解决ING。。。。。 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |