第二个 Applet:
还是在 SQL Server 的Recruitment 数据库中,有一张 ExternalCandidate表和一张 PassWord 表。ExternalCandidate 表的相关内容如下:cCandidateCode vFirstName           vLastName            cPositionCode dTestDate                   siTestScore dInterviewDate              cInterviewer         vInterviewComments                                                  cRating 
-------------- -------------------- -------------------- ------------- --------------------------- ----------- --------------------------- -------------------- -------------------------------------------------------------------
000001         Angela               Smith                0001          1997-05-09 00:00:00.000     80          1997-05-15 00:00:00.000     NULL                 NULL                                                                   8
000002         Barbara              Johnson              0005          1997-08-21 00:00:00.000     82          1997-08-28 00:00:00.000     000001               Good Communication skill                                               9
000003         Betty                Williams             0010          1998-05-09 00:00:00.000     70          1998-05-20 00:00:00.000     000001               Good presentation skill                                                8
000004         Carol                Jones                0012          1998-05-09 00:00:00.000     45          1998-05-24 00:00:00.000     000001               Quick Learner                                                          6
000005         Catherine            Roberts              0007          1998-05-09 00:00:00.000     74          1998-05-28 00:00:00.000     000001               Good at planning                                                       7
000010         David                Moore                0001          1998-08-14 00:00:00.000     92          1998-08-21 00:00:00.000     000006               Takes lots of Initiative                                               9
000011         Deborah              Taylor               0007          1998-08-14 00:00:00.000     88          1998-08-21 00:00:00.000     000006               Has worked as good team member                                         8
000012         Donna                Anderson             0010          1998-08-14 00:00:00.000     83          1998-08-21 00:00:00.000     0000011              Hard working                                                           8
000014         Elizabeth            Jackson              0013          1998-09-13 00:00:00.000     65          1998-09-21 00:00:00.000     000001               Good presentation skills                                               6
000016         Helen                White                0015          1998-12-15 00:00:00.000     94          1998-12-20 00:00:00.000     000006               Quick Learner                                                          9
000018         Jennifer             Martin               0015          1998-12-20 00:00:00.000     97          1998-12-23 00:00:00.000     000006               Good at planning and good analytical skills                            9
000021         Joseph               Martinez             0014          1999-01-22 00:00:00.000     81          1999-01-26 00:00:00.000     000006               Commited and Hard working                                              8
000022         Joyce                Phillips             0001          1999-01-22 00:00:00.000     61          1999-01-26 00:00:00.000     000001               Long term potential                                                    6
000026         Linda                Lewis                0014          1999-01-22 00:00:00.000     69          1999-01-26 00:00:00.000     000006               Helpfull in nature                                                     6
000029         Maria                Hall                 0008          1999-02-07 00:00:00.000     57          1999-02-09 00:00:00.000     000011               Customer oriented                                                      8
000033         Nancy                King                 0006          1999-03-07 00:00:00.000     76          1999-03-06 00:00:00.000     000001               Needs to improve in communication,but commited to the job              7
000035         Paul                 Lopez                0006          1999-03-08 00:00:00.000     96          1999-03-14 00:00:00.000     000001               Hard working but needs to improve in communication skill               9
000038         Ruth                 Green                0003          1999-03-08 00:00:00.000     88          1999-03-10 00:00:00.000     000011               Helpfull in nature                                                     8
000039         Sandra               Adams                0003          1999-02-14 00:00:00.000     55          1999-02-20 00:00:00.000     000001               Long term potential                                                    6
000040         Sarah                Baker                0002          1999-02-15 00:00:00.000     67          1999-02-21 00:00:00.000     000011               Needs to improve in communication skills                               6
000045         William              Perez                0002          1999-03-30 00:00:00.000     78          1999-04-14 00:00:00.000     000006               Customer oriented                                                      8
000046         David                Cooper               0003          1999-03-30 00:00:00.000     89          1999-04-07 00:00:00.000     000006               Long term potential, commited and hardworking                          9
000047         Peter                Prescott             0015          1999-03-30 00:00:00.000     55          NULL                        NULL                 NULL                                                                   5
000049         Jane                 Schaffer             0002          1999-05-16 00:00:00.000     84          NULL                        NULL                 NULL                                                                   8(24 row(s) affected)表 PassWord 的相关内容如下:cCandidateCode vFirstName           vLastName            vPassWord
-------------- -------------------- -------------------- 
000001         Angela               Smith                123
000002         Barbara              Johnson              456
000003         Betty                Williams             5842
000004         Carol                Jones                3548
000005         Catherine            Roberts              95214
000010         David                Moore                2554
000011         Deborah              Taylor               2486
000012         Donna                Anderson             22448
000014         Elizabeth            Jackson              6995
000016         Helen                White
000018         Jennifer             Martin
000021         Joseph               Martinez
000022         Joyce                Phillips
000026         Linda                Lewis
000029         Maria                Hall
000033         Nancy                King
000035         Paul                 Lopez
000038         Ruth                 Green
000039         Sandra               Adams
000040         Sarah                Baker
000045         William              Perez
000046         David                Cooper
000047         Peter                Prescott
000049         Jane                 Schaffer(24 row(s) affected)
要求在有密码的用户查询自己的情况时,验证密码,并能给出错误提示。
密码正确的用户将得到表ExternalCandidate中的相关内容。希望能够显示在以列名为一个个的标签标签、相对应内容显示在紧随其后的文本框中的形式。
如果表 PassWord 的 vPassWord 列,在表 ExternalCandidate 中已存在,又如何实现呢?
似乎简单的问题也被我讲得繁杂了,唉~!希望

解决方案 »

  1.   

    其实,看下,发现最不晓得的是两个问题。1。不晓得怎么用 table 来显示数据库记录,好晕!@@@@@2。不晓得怎么用密码验证!倒~!
      

  2.   

    1、看我给你的留言,如果没有,留下你的邮箱吧,我给你发个例子过去。
    2、密码验证很简单,你可以做个界面,设置输入用户名文本框和密码框,通过文本框读取数据库,取出其对应记录的密码字段,再比较密码框中输入的字段,相等就给予显示处理不就得了?比较时注意你的数据库密码字段是否是char类型,如果是需要对读取的字段进行trim()去掉追尾空格。
      

  3.   

    得了,贴出来算了。注意将例中的数据获取结果集部分换成你自己的
    另外private static boolean SCROLLABLE = false;是用来表示你的数据库是否支持滚动光标,如果是,就定义为true。/**
     * @version 1.00 1999-07-17
     * @author Cay Horstmann
     */
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;public class ResultSetTable
    {  public static void main(String[] args)
       {  JFrame frame = new ResultSetFrame();
          frame.show();
       }
    }/* this class is the base class for the scrolling and the
       caching result set table model. It stores the result set
       and its metadata.
    */abstract class ResultSetTableModel extends AbstractTableModel
    {  public ResultSetTableModel(ResultSet aResultSet)
       {  rs = aResultSet;
          try
          {  rsmd = rs.getMetaData();
          }
          catch(SQLException e)
          {  System.out.println("Error " + e);
          }
       }   public String getColumnName(int c)
       {  try
          {  return rsmd.getColumnName(c + 1);
          }
          catch(SQLException e)
          {  System.out.println("Error " + e);
             return "";
          }
       }   public int getColumnCount()
       {  try
          {  return rsmd.getColumnCount();
          }
          catch(SQLException e)
          {  System.out.println("Error " + e);
             return 0;
          }
       }   protected ResultSet getResultSet()
       {  return rs;
       }   private ResultSet rs;
       private ResultSetMetaData rsmd;
    }/* this class uses a scrolling cursor, a JDBC 2 feature
    */class ScrollingResultSetTableModel extends ResultSetTableModel
    {  public ScrollingResultSetTableModel(ResultSet aResultSet)
       {  super(aResultSet);
       }   public Object getValueAt(int r, int c)
       {  try
          {  ResultSet rs = getResultSet();
             rs.absolute(r + 1);
             return rs.getObject(c + 1);
          }
          catch(SQLException e)
          {  System.out.println("Error " + e);
             return null;
          }
       }   public int getRowCount()
       {  try
          {  ResultSet rs = getResultSet();
             rs.last();
             return rs.getRow();
          }
          catch(SQLException e)
          {  System.out.println("Error " + e);
             return 0;
          }
       }
    }/* this class caches the result set data; it can be used
       if scrolling cursors are not supported
    */class CachingResultSetTableModel extends ResultSetTableModel
    {  public CachingResultSetTableModel(ResultSet aResultSet)
       {  super(aResultSet);
          try
          {  cache = new ArrayList();
             int cols = getColumnCount();
             ResultSet rs = getResultSet();         /* place all data in an array list of Object[] arrays
                We don't use an Object[][] because we don't know
                how many rows are in the result set
             */         while (rs.next())
             {  Object[] row = new Object[cols];
                for (int j = 0; j < row.length; j++)
                   row[j] = rs.getObject(j + 1);
                cache.add(row);
             }
          }
          catch(SQLException e)
          {  System.out.println("Error " + e);
          }
       }   public Object getValueAt(int r, int c)
       {  if (r < cache.size())
             return ((Object[])cache.get(r))[c];
          else
             return null;
       }   public int getRowCount()
       {  return cache.size();
       }   private ArrayList cache;
    }class ResultSetFrame extends JFrame
       implements ActionListener
    {  public ResultSetFrame()
       {  setTitle("ResultSet");
          setSize(300, 200);
          addWindowListener(new WindowAdapter()
             {  public void windowClosing(WindowEvent e)
                {  System.exit(0);
                }
             } );      /* find all tables in the database and add them to
             a combo box
          */      Container contentPane = getContentPane();
          tableNames = new JComboBox();
          tableNames.addActionListener(this);
          JPanel p = new JPanel();
          p.add(tableNames);
          contentPane.add(p, "North");      try
          {  Class.forName("com.pointbase.jdbc.jdbcDriver");
                // force loading of driver
             String url = "jdbc:pointbase:corejava";
             String user = "PUBLIC";
             String password = "PUBLIC";
             con = DriverManager.getConnection(url, user,
                password);
             if (SCROLLABLE)
                stmt = con.createStatement(
                   ResultSet.TYPE_SCROLL_INSENSITIVE,
                   ResultSet.CONCUR_READ_ONLY);
             else
                stmt = con.createStatement();
             DatabaseMetaData md = con.getMetaData();
             ResultSet mrs = md.getTables(null, null, null,
                new String[] { "TABLE" });
             while (mrs.next())
                tableNames.addItem(mrs.getString(3));
              mrs.close();
          }
          catch(ClassNotFoundException e)
          {  System.out.println("Error " + e);
          }
          catch(SQLException e)
          {  System.out.println("Error " + e);
          }
       }   public void actionPerformed(ActionEvent evt)
       {  if (evt.getSource() == tableNames)
          {  // show the selected table from the combo box         if (scrollPane != null)
                getContentPane().remove(scrollPane);
             try
             {  String tableName
                   = (String)tableNames.getSelectedItem();
                if (rs != null) rs.close();
                String query = "SELECT * FROM " + tableName;
                rs = stmt.executeQuery(query);
                if (SCROLLABLE)
                   model = new ScrollingResultSetTableModel(rs);
                else
                   model = new CachingResultSetTableModel(rs);            JTable table = new JTable(model);
                scrollPane = new JScrollPane(table);
                getContentPane().add(scrollPane, "Center");
                pack();
                doLayout();
             }
             catch(SQLException e)
             {  System.out.println("Error " + e);
             }
          }
       }   private JScrollPane scrollPane;
       private ResultSetTableModel model;
       private JComboBox tableNames;
       private JButton nextButton;
       private JButton previousButton;
       private ResultSet rs;
       private Connection con;
       private Statement stmt;   private static boolean SCROLLABLE = false;
          // set to true if your database supports scrolling cursors
    }
      

  4.   

    你可以看一下JAVA核心特性卷二种关于表的那部分内容
      

  5.   

    真的是初学啊,骗你我去撞墙!想了几天了,我的教科书上没得,又没得相应的例子,所以…………早知道就去买本《Java2类库》或《java核心技术卷2高级特性》了!唉~!
      

  6.   

    结帖,多谢shihb、wangwenyou、alphazhao和lizl的关注!alphazhao(绿色咖啡)得90分,lizl(红星闪闪)得10分!昨天晚上上不来,这几天又比较忙,不好意思!^o^