QuestionQuestion

Transcribed TextTranscribed Text

(Display table contents) Write a program that displays the content for a giventable. As shown below, you enter a table and click the Show Contentsbutton to display the table contents in the text area. The column names and table names must be read from Metadata. Choose Table to Display x Table Name enrollment Show Contents ssn courseld dateRegistered grade 444111110 11111 2009-08-12 A 444111110 11112 2009-08-12 B 444111110 11113 2009-08-12 C 444111111 11111 2009-08-12 D 444111111 11112 2009-08-12 F 11112 2000 01 19 A

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.awt.Font;
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.ArrayList;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

public class GUI extends JFrame {

    private Connection connection;

    /**
    * Creates new form GUI
    */
    public GUI() {
       initComponents();
       jTextAreaOutput.setFont(new Font("Monospaced", Font.PLAIN, 12));
       try {
            connecting();
       } catch (SQLException e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
            System.exit(0);
       }
    }

    private void connecting() throws SQLException {
       connection = DriverManager.getConnection("jdbc:sqlserver://s16988308.onlinehome-server.com:1433;"
                + "databaseName= CUNY_DB; integratedSecurity=false;",
                "cst3613", "password1");
       // Create a statement
       Statement statement = connection.createStatement();

       // get name of all table in the database
       ResultSet resultSet = statement.executeQuery("select table_name from CUNY_DB.INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE'");
       while (resultSet.next()) {
            jComboBoxTable.addItem(resultSet.getString(1));
       }
    }

    /**
    * create the GUI
    */
    private void initComponents() {

       jScrollPane1 = new JScrollPane();
       jTextAreaOutput = new JTextArea();
       jLabel1 = new JLabel();
       jComboBoxTable = new JComboBox<>();
       jButtonShow = new JButton();

       setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
       setTitle("Choose Table to Display");

       jTextAreaOutput.setColumns(20);
       jTextAreaOutput.setRows(5);
       jScrollPane1.setViewportView(jTextAreaOutput);

       jLabel1.setText("Table Name");

       jButtonShow.setText("Show Contents");
       jButtonShow.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                jButtonShowActionPerformed(evt);
            }
       });

       GroupLayout layout = new GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
       layout.setHorizontalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addComponent(jScrollPane1)
                        .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                               .addContainerGap(176, Short.MAX_VALUE)
                               .addComponent(jLabel1)
                               .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                               .addComponent(jComboBoxTable, GroupLayout.PREFERRED_SIZE, 99, GroupLayout.PREFERRED_SIZE)
                               .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                               .addComponent(jButtonShow)
                               .addGap(152, 152, 152))
       );
       layout.setVerticalGroup(
                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                               .addContainerGap()
                               .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel1)
                                        .addComponent(jComboBoxTable, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jButtonShow))
                               .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                               .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))
       );

       pack();
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$56.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats