当前位置: 代码迷 >> J2SE >> 看下这段代码错在那里了?该怎么解决
  详细解决方案

看下这段代码错在那里了?该怎么解决

热度:10   发布时间:2016-04-24 14:49:30.0
看下这段代码错在那里了?
package   lucky;

import   javax.swing.*;

import   java.awt.*;
import   java.awt.event.*;
import   java.sql.*;
import   java.util.Vector;

public   class   findStu   extends   JFrame   {

/**
  *   查询用户
  */
private   Connection   con;
private   ResultSet   rs;
private   Statement   stmt;
private   ResultSetMetaData   rsMetaData;

private   Choice   check;
private   JTextField   term;
private   JTable   table;
private   String   search;
private   String   conlon;
private   String   strSql;
boolean   flag   =   false;

findStu()   {

super( "学生查询 ");
String   url   =   "jdbc:mysql://localhost:3306/lucky ";
String   name   =   "root ";
String   pass   =   "lala ";

try   {
Class.forName( "com.mysql.jdbc.Driver ");
con   =   DriverManager.getConnection(url,   name,   pass);

}   catch   (ClassNotFoundException   e)   {
e.getStackTrace();
System.exit(1);
}   catch   (SQLException   e)   {
e.getStackTrace();
System.exit(1);
}

JPanel   findpanel   =   new   JPanel();
findpanel.setLayout(new   FlowLayout());
check   =   new   Choice();

check.add( "StuNO ");
check.add( "StuName ");
check.add( "sex ");
check.add( "birthred ");
check.add( "magar ");
check.add( "dep ");

term   =   new   JTextField();
term.setPreferredSize(new   Dimension(120,   20));

JButton   onebut   =   new   JButton( "查询 ");
onebut.addActionListener(new   ActionListener()   {
public   void   actionPerformed(ActionEvent   e)   {
flag   =   true;
getTable();
}
});

JButton   allbut   =   new   JButton( "全部 ");
allbut.addActionListener(new   ActionListener()   {
public   void   actionPerformed(ActionEvent   e)   {
flag   =   false;
getTable();
}
});

findpanel.add(check,   FlowLayout.LEFT);
findpanel.add(term);
findpanel.add(onebut);
findpanel.add(allbut);

table   =   new   JTable();

Container   c   =   getContentPane();

c.setLayout(new   BorderLayout());

c.add(findpanel,   BorderLayout.NORTH);
c.add(table,   BorderLayout.CENTER);
addWindowListener(new   WindowAdapter()   {
public   void   Closing(WindowEvent   e)   {
closecon();
System.exit(1);
}
});
setResizable(false);
setSize(450,   350);
OnScreen();
show();
}

public   void   getTable()   {
if   (flag   ==   true)   {
try   {
search   =   term.getText();
conlon   =   check.getSelectedItem();
strSql   =   "select   *   from   student   where   "   +   conlon   +   "= "   +   search
  相关解决方案