Как определить ошибки в Java - PullRequest
0 голосов
/ 31 мая 2010

Я просто новичок в Java.Есть ли у вас какие-либо советы по определению ошибок.Я пытаюсь подключиться к базе данных mysql derby.Я не знаю, как определить ошибку, там нет красной линии, но есть окно сообщения, которое появляется, когда я пытаюсь запустить программу.Все, что я хочу сделать, это отобразить первую запись в базе данных.Все, что я получаю, это в выводе:

E: \ Users \ users.netbeans \ 6.8 \ var \ cache \ executor-snippets \ run.xml: 45:

package Employees;

import java.sql.Statement;

import javax.swing.JOptionPane;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
/**
 *
 * @author Nrew
 */
public class Students extends javax.swing.JFrame {

    Connection con;
   Statement stmt;
   ResultSet rs;


    /** Creates new form Students */
    public Students() {
        initComponents();

DoConnect();

    }

    public void DoConnect(){
          try {
            String host= "jdbc:derby://localhost:1527/YURA";
String uname = "bart";
String pword = "12345";
con = DriverManager.getConnection(host, uname, pword);

 stmt = con.createStatement( );
String SQL = "SELECT * FROM APP.XROSS";
 rs = stmt.executeQuery(SQL);
rs.next();

rs.next( );
int ids = rs.getInt("IDNUM");
String idz = Integer.toString(ids);
String fname = rs.getString("FNAME");
String lname = rs.getString("LNAME");
String course = rs.getString("COURSE");
String skul = rs.getString("SCHOOL");
String gen = rs.getString("GENDER");

TextIDNUM.setText(idz);
TextFNAME.setText(fname);
TextLNAME.setText(lname);
textCOURSE.setText(course);
textSCHOOL.setText(skul);
textGENDER.setText(gen);







        }
        catch (SQLException err) {
          JOptionPane.showMessageDialog(Students.this, err.getMessage());



    }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        TextIDNUM = new javax.swing.JTextField();
        TextFNAME = new javax.swing.JTextField();
        TextLNAME = new javax.swing.JTextField();
        textCOURSE = new javax.swing.JTextField();
        textSCHOOL = new javax.swing.JTextField();
        textGENDER = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(116, 116, 116)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(textGENDER, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textSCHOOL, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textCOURSE, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TextLNAME, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TextFNAME, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TextIDNUM, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE))
                .addContainerGap(243, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(TextIDNUM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(TextFNAME, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(TextLNAME, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(textCOURSE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(textSCHOOL, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(textGENDER, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(67, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Students().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JTextField TextFNAME;
    private javax.swing.JTextField TextIDNUM;
    private javax.swing.JTextField TextLNAME;
    private javax.swing.JTextField textCOURSE;
    private javax.swing.JTextField textGENDER;
    private javax.swing.JTextField textSCHOOL;
    // End of variables declaration

}

1 Ответ

3 голосов
/ 31 мая 2010

Напечатайте stackTrace как это:

catch (SQLException err) {
    err.printStackTrace();  // <-- add this

    JOptionPane.showMessageDialog(Students.this, err.getMessage());
}
...