问题描述
点击按钮没有反映packageappmedicine.view;importjava.awt.Container;publicclassagencyMessageextendsJInternalFrame{/****/privatestaticfinallongserialVersionUID=1005625849656072748L;publicJTextFieldtextField;privateJTabletable;/***Launchtheapplication.*/publicstaticvoidmain(String[]args){EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{agencyMessageframe=newagencyMessage();frame.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/***Createtheframe.*@throwsSQLException*@throwsClassNotFoundException*/publicagencyMessage()throwsClassNotFoundException,SQLException{setTitle("u7ECFu529Eu4EBAu4FE1u606Fu67E5u8BE2");setBounds(100,100,615,394);JPanelpanel=newJPanel();getContentPane().add(panel,BorderLayout.NORTH);JLabellabel=newJLabel("u7ECFu529Eu4EBAu7F16u53F7uFF1A");panel.add(label);textField=newJTextField();panel.add(textField);textField.setColumns(10);JButtonbutton=newJButton("u786Eu5B9A");button.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){try{getSearchVector();}catch(SQLExceptione1){//TODO自动生成的catch块e1.printStackTrace();}}});panel.add(button);finalJScrollPanescrollPane=newJScrollPane();getContentPane().add(scrollPane,BorderLayout.CENTER);VectordataVector=null;table=newJTable(dataVector,getAgencyColumnVector());scrollPane.setViewportView(table);}publicVectorgetSearchVector()throwsSQLException{Connectionconn=null;java.sql.Statementstmt=null;conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=db_medicine","sa","5512834panni");stmt=conn.createStatement();Stringname=textField.getText();Stringsql=null;sql="select*fromagencywhereano='"+name+"'";//定义SQL语句ResultSetrs=stmt.executeQuery(sql);System.out.print(sql);VectorsearchVector=newVector();VectordataVector=newVector();while(rs.next()){VectorrowVector=newVector();for(inti=1;i<=5;i++){if(i==2||i==4){rowVector.add(String.valueOf(rs.getString(i)));}else{rowVector.add(rs.getString(i));}}dataVector.add(rowVector);}returndataVector;}VectorgetAgencyColumnVector(){VectorcolumnVector=newVector();columnVector.add("编号");columnVector.add("姓名");columnVector.add("性别");columnVector.add("电话");columnVector.add("备注");returncolumnVector;}}
解决方案
解决方案二:
没有加载数据库驱动
解决方案三:
加载了,别人说是调用Vector的问题