日期:2014-05-20  浏览次数:20899 次

这个程序为什么到这条语句不能执行了。
错误信息:
java.sql.SQLException:   Column   not   found
at   sun.jdbc.odbc.JdbcOdbcResultSet.findColumn(JdbcOdbcResultSet.java:1849)
at   sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:410)
at   DisplayQueryResults.getNextRow(DisplayQueryResults.java:125)
at   DisplayQueryResults.displayResultSet(DisplayQueryResults.java:107)
at   DisplayQueryResults.getTable(DisplayQueryResults.java:89)
at   DisplayQueryResults. <init> (DisplayQueryResults.java:77)
at   DisplayQueryResults.main(DisplayQueryResults.java:144)

程序代码:
import   java.awt.BorderLayout;
import   java.awt.Container;
import   java.awt.event.ActionEvent;
import   java.awt.event.ActionListener;
import   java.awt.event.WindowAdapter;
import   java.awt.event.WindowEvent;

import   java.sql.Connection;
import   java.sql.DriverManager;
import   java.sql.ResultSet;
import   java.sql.ResultSetMetaData;
import   java.sql.SQLException;
import   java.sql.Statement;
import   java.util.Vector;

import   javax.swing.JButton;
import   javax.swing.JFrame;
import   javax.swing.JOptionPane;
import   javax.swing.JPanel;
import   javax.swing.JScrollPane;
import   javax.swing.JTable;
import   javax.swing.JTextArea;


  public   class   DisplayQueryResults   extends   JFrame  
  {
private   Connection   con;
private   Statement   stmt;
private   ResultSet   resultset;
private   ResultSetMetaData   rsmd;
private   JTable   table;
private   JTextArea   input;
private JButton   submit;

DisplayQueryResults(   )
{
super();


try   {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
  }
catch   (ClassNotFoundException   ee)  
{    
System.err.println( "加载驱动失败! ");
ee.printStackTrace();
System.exit(1);
  }  
try{
  con=DriverManager.getConnection( "jdbc:odbc:bank_data ", "sa ", "123456 ");
        }
  catch(SQLException   ex)    
          {
    System.out.println( "\n******SQLException   catch********\n ");
    while(ex!=null)
    {
System.out.println( "SQLState: "+ex.getSQLState());
System.out.println( "Message: "+ex.getMessage());
System.out.println( "Vendor: "+ex.getErrorCode());
ex=   ex.getNextException();
System.exit(1);
    }
}
String   test= "select   *   from   user_table ";
input   =   new   JTextArea(test,4,30);
submit=new   JButton( "查询 ");
submit.addActionListener(new   ActionListener(){public   void   actionPerformed(ActionEvent   e){getTable();}});
JPanel   toppanel=new   JPanel();
toppanel.setLayout(new   BorderLayout());
toppanel.add(new   JScrollPane(input),BorderLayout.CENTER);
toppanel.add(submit,BorderLayout.SOUTH);
table=   new   JTable();
Container   c=getContentPane();
c.setLayout(new   BorderLayout());
c.add(toppanel,BorderLayout.NORTH);