本文介绍了请帮助我解决矢量问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

import java.awt.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;

public class JTableDatabase extends JFrame{
    public JTableDatabase() {
        Vector columnNames = new Vector();
        Vector data = new Vector();

        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection connect =DriverManager.getConnection("jdbc:odbc:employeedsn");

            String sql = "Select * from emp";
            Statement stmt = connect.createStatement();
            ResultSet rs = stmt.executeQuery( sql );
            ResultSetMetaData md = rs.getMetaData();
            int columns = md.getColumnCount();
            for (int i = 1; i <= columns; i++) {
                columnNames.addElement( md.getColumnName(i) );
            }
            //my Problem start here
            while (rs.next()) {
                Vector row = new Vector(columns);
                for (int i = 1; i <= columns; i++) {
                    row.addElement( rs.getObject(i) );
                }
                data.addElement( row );
            }
            //and ends here
            rs.close();
            stmt.close();
        }
        catch(Exception e) {
            System.out.println( e );
        }
        JTable table = new JTable(data, columnNames);

        JScrollPane scrollPane = new JScrollPane( table );
        getContentPane().add( scrollPane );

        JPanel buttonPanel = new JPanel();
        getContentPane().add( buttonPanel, BorderLayout.SOUTH );
    }

    public static void main(String[] args) {

        JTableDatabase frame = new JTableDatabase();
        frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
        frame.pack();
        frame.setTitle("Information Table");
        frame.setVisible(true);
        }
}





我只是想知道循环中发生了什么。

请帮我解决我的问题

提前使用Thanx



I Just want to know what is going in while loop.
Please help me in solving my problem
Thanx in advance

推荐答案


这篇关于请帮助我解决矢量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 10:46