-1

I am working on a Swing based small project. In this project I want to open another window when user log-in successfully but when I click log-in button an exception occurred, like "Illegal attempt to exit early", while my database connection is well because when I show message dialog then it shows successful log-in. Here is my code.

package org.Core.Art;

import java.awt.Component;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;
import java.sql.*;
import javax.swing.*;
import org.openide.util.Exceptions;

public final class CoreTopComponent extends TopComponent { 

    private String password;
    private String pwd;
    private Component jPasswordField1;
    private Component jButton1;
    //private Object text_password;

    public CoreTopComponent() {
        initComponents();
    } 

    private void ClickActionPerformed(java.awt.event.ActionEvent evt) {                
        // TODO add your handling code here:
        Object  password = text_password.getText();       

        String query = "Select * from assistant where pass = '"+password+"'";

        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/auto_lube","root", "mehar");    
            Statement stmt = conn.createStatement();
            stmt.execute(query);    
            ResultSet rs = stmt.getResultSet();
            boolean recordfound = rs.next();

            if (recordfound) {
                Login regFace = new Login();
                regFace.setVisible(true);
                dispose(); 
                //JOptionPane.showMessageDialog(null,"You are login successfully");
            } else {
                JOptionPane.showMessageDialog(null,"Try again");
                // new Login_fram().setVisible(true);
            }

        conn.close();

        } catch(java.lang.ClassNotFoundException ex) {
            JOptionPane.showMessageDialog(null,"Exception Occured"+ex.getMessage());
        } catch(Exception ex) {
            JOptionPane.showMessageDialog(null,"Exception Occured"+ex.getMessage());    
        }
    }

    private void text_passwordActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        Object  password = text_password;
    }

    public static void main(String args[]) {
        CoreTopComponent core = new CoreTopComponent();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CoreTopComponent().setVisible(true);
            }
        });
     }
}

And my other class is Login.java and I want when user click log_in button if record found then open a new window or Login.java.

dic19
  • 17,821
  • 6
  • 40
  • 69
Suraj Ali
  • 21
  • 7
  • If you get exceptions then post a stacktrace output that has the exact exception. – takendarkk Sep 07 '14 at 06:06
  • Message: Exception OccuredIllegal attempt to exit early; this exception occured – Suraj Ali Sep 07 '14 at 06:09
  • i am new in java swing please guide me and share any link thanks. – Suraj Ali Sep 07 '14 at 06:11
  • 2
    1) Always copy/paste error or exception output. 2) See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) 3) Use a logical & consistent code formatting style! The code indentation is intended to help people follow the program flow. 4) A single blank line of white space is *always* enough. Blank lines after `{` or before `}` are also typically redundant. – Andrew Thompson Sep 07 '14 at 07:12

1 Answers1

1

At these lines:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/auto_lube","root", "mehar")

Note you're trying to connect to a MySQL database using JdbcOdbcDriver which is not correct but probably the exception's cause. You should use MysQL Connector instead. Besides JDBC-ODBC bridge is deprecated since JDK8. See Removal of JDBC ODBC bridge in java 8

There are some other JDBC tips you can follow in this answer. In a nutshell:


Off-topic

Please note there are several conceptual errors in your code. For example this SQL query (note the proper way of using prepared statements):

String query = "SELECT * FROM assistant WHERE pass = ?";

This query will return all records where password is equal to some parameter, so if two or more people have the same password it will return more than a single record. Unlikely, yes, but possible. Log-in systems are based on user names and passwords, so you should query for user name and then check if password is valid or not. Not to mention that password should not be stored as plain text but at least encrypted (better if hashed).

On the other hand based on your code it is really hard to tell if you are using Swing standard components or some other API based on Swing. I mean, what is org.openide.*? Where are the imports for Swing components?

Finally, if you still having problems, pelase post the exception's stack trace.

Community
  • 1
  • 1
dic19
  • 17,821
  • 6
  • 40
  • 69