-2

データベースからデータを取得してコンソールに出力する際に​​問題が発生しています。この情報を取得する代わりに String sql = "SELECT * FROM COMPANY"; 私の出力はこれです

org.sqlite.RS@18893021
1 John javax.swing.JLabel[,0,42,195x16,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=Age: ,verticalAlignment=CENTER,verticalTextPosition=CENTER] javax.swing.JLabel[,0,84,195x16,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=Address: ,verticalAlignment=CENTER,verticalTextPosition=CENTER] javax.swing.JLabel[,0,126,195x16,invalid,alignmentX=0.0,alignmentY=0.0,border=,flags=8388608,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizontalAlignment=LEADING,horizontalTextPosition=TRAILING,iconTextGap=4,labelFor=,text=Salary: ,verticalAlignment=CENTER,verticalTextPosition=CENTER]

私のコードは次のとおりです。

package userinterface;

import javax.swing.JFrame;

import java.awt.FlowLayout;

import javax.swing.JButton;

import javax.swing.JDialog;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

import backend.SQLiteDb;

import business.Person;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.BorderLayout;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class GUI {

    static SQLiteDb db;

    public static void main(String[] args) {

        final JFrame jframe = new JFrame();

        JButton btnEnterInfo = new JButton("Enter Info");

        jframe.getContentPane().add(btnEnterInfo, BorderLayout.CENTER);

        jframe.setVisible(true);

        jframe.setSize(300, 300);

        btnEnterInfo.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {

                JLabel fullName = new JLabel("Full Name: ");

                JTextField nameField = new JTextField();

                JLabel age = new JLabel("Age: ");

                JTextField ageField = new JTextField();

                JLabel address = new JLabel("Address: ");

                JTextField addressField = new JTextField();

                JLabel salary = new JLabel("Salary: ");

                JTextField salaryField = new JTextField();

                Object[] ob = { fullName, nameField, age, ageField, address,
                        addressField,

                        salary, salaryField };

                int result = JOptionPane.showConfirmDialog(null, ob, "Part 5",

                JOptionPane.OK_CANCEL_OPTION);

                jframe.getContentPane().setLayout(new FlowLayout());

                if (result == JOptionPane.OK_OPTION) {

                    db = new SQLiteDb();

                    db.createPersonnelTable();
                    String fullName1 = nameField.getText();
                    String userAge = ageField.getText();
                    String userAddress = addressField.getText();
                    String userSalary = salaryField.getText();
                    Person person = new Person(fullName1, Integer
                            .parseInt(userAge), userAddress,

                    Double.parseDouble(salaryField.getText()));

                    db.addPerson(person);

                    String sql = "SELECT * FROM COMPANY";

                    Statement stmt = null;

                    try {
                        java.sql.Statement s;

                        Connection connection = DriverManager
                                .getConnection("JDBC:sqlite:Andy.db");
                        stmt = connection.createStatement();
                        ResultSet rs = stmt.executeQuery(sql);
                        while (rs.next()) {
                            int id_col = rs.getInt("ID");
                            String name = rs.getString("name");
                            int age1 = rs.getInt("Age");
                            float address1 = rs.getFloat("Address");
                            double salary1 = rs.getInt("Salary");
                            System.out.println(rs);
                            String output = id_col + " " + name + " " +          age + " " + address + " " + salary;
                            System.out.println(output);
                            rs.close();
                        }
                    } catch (SQLException ee) {
                        System.out.println("ee error");
                        ee.printStackTrace();

                    } finally {
                        if (stmt != null) {
                            try {
                                stmt.close();
                            } catch (SQLException e1) {
                                // TODO Auto-generated catch block
                                System.out.println("e1 error");
                             e1.printStackTrace();
                            }
                        }
                    }


                }

            }
        });

    }

    public static void viewTable(Connection con, String dbName)
            throws SQLException {

    }
4

1 に答える 1