尝试构建时布尔错误java控制台

时间:2014-09-17 18:55:43

标签: java netbeans jar build

当我尝试清理和构建项目时,我似乎在以下java代码中遇到了java错误:

public class DisplayPerson extends javax.swing.JFrame{

String driverName = "net.sourceforge.jtds.jdbc.Driver";
   String serverName = "xx";
                String serverPort = "xx";
                String database = serverName + ":" + serverPort;
                String url = "jdbc:jtds:sqlserver:/" + database;
                String username = "xx";
                String password = "xx";

    public DisplayPerson() throws SQLException {
           ArrayList columnNames = new ArrayList();
        ArrayList data = new ArrayList();


    try {

        Class.forName(driverName);
        Connection connection = DriverManager.getConnection(url, username, password);

        // Create and execute an SQL statement that returns some data.
        String SQL = "";
        Statement stmt = connection.createStatement();
        ResultSet rs = stmt.executeQuery(SQL);
        ResultSetMetaData  rsmetadata = rs.getMetaData();

        int columns = rsmetadata.getColumnCount();


        //  Get column names
            for (int i = 1; i <= columns; i++)
            {
            boolean add;
            add = columnNames.add( rsmetadata.getColumnName(i) );
            }

            //  Get row data
            while (rs.next())
            {
                ArrayList row;
            row = new ArrayList(columns);

                for (int i = 1; i <= columns; i++)
                {
                    boolean add;
                    add = row.add( rs.getObject(i) );
                }

            boolean add;
            add = data.add( row );
            }
        }
        catch (SQLException e)
        {
            System.out.println( e.getMessage() );
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DisplayPerson.class.getName()).log(Level.SEVERE, null, ex);
        }

    // Create Vectors and copy over elements from ArrayLists to them
        // Vector is deprecated but I am using them in this example to keep 
        // things simple - the best practice would be to create a custom defined
        // class which inherits from the AbstractTableModel class
        Vector columnNamesVector = new Vector();
        Vector dataVector = new Vector();

        for (int i = 0; i < data.size(); i++)
        {
            ArrayList subArray = (ArrayList)data.get(i);
            Vector subVector = new Vector();
            for (int j = 0; j < subArray.size(); j++)
            {
                boolean add;
                add = subVector.add(subArray.get(j));
            }
               boolean add;
               add = dataVector.add(subVector);
        }

        for (int i = 0; i < columnNames.size(); i++ )
               boolean add 
                       add = columnNamesVector.add(columnNames.get(i));

        //  Create table with database data    
        JTable table;
            table = new JTable(dataVector, columnNamesVector)

    {

        public Class getColumnClass(int column)
        {
            for (int row = 0; row < getRowCount(); row++)
            {
                Object o = getValueAt(row, column);

                if (o != null)
                {
                    return o.getClass();
                }
            }

            return Object.class;
        }
    };

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

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


    }

1 个答案:

答案 0 :(得分:0)

您可以通过更改此代码来避免此错误

 for (int i = 1; i <columnNames.size(); i++)

       boolean add //here is a missing semicolon
       add = columnNamesVector.add(columnNames.get(i));//variable declaration not allowed here

如下

 for (int i = 0; i < columnNames.size(); i++ ){
         boolean add ;
         add = columnNamesVector.add(columnNames.get(i));
  }

离开方括号不是一个好主意。