0

I am working in swing based project.In which i want to open a new window when user log-in successfully but when i click log-in button exception occurred"org.net-bean.ExitSecurityException:Illegal attempt to exit early" i also check my record using print out everything is working well but i have no idea how to fix this problem.Here is my code.

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;

class CoreTopComponent extends TopComponent {

    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

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

    public CoreTopComponent() {
        initComponents();
        conn = mysqlconnect.ConnecrDb();
    }

    private void ClickActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
        Object password = text_password.getText();
        String sql = "Select * from assistant where pass =?";

        try {
            pst = conn.prepareStatement(sql);
            pst.setString(1, text_password.getText());
            rs = pst.executeQuery();

            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "You are login successfully");
                //setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                org.openide.LifecycleManager.getDefault();
                Login s = new Login();
                s.setVisible(true);
            } else {
                JOptionPane.showMessageDialog(null, "You are not login successfully");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        } finally {
            try {
                rs.close();
                pst.close();
            } catch (Exception e) {
            }
        }
    }

    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);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JToggleButton Click;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JOptionPane jOptionPane1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPasswordField text_password;
}

And my mysql connection code is here

package org.Core.Art;
import java.sql.*;
import javax.swing.*;  

public class mysqlconnect {
    Connection conn = null;
    public static Connection ConnecrDb() {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/auto_lube", "root", "mehar");
            JOptionPane.showMessageDialog(null, "Connection established");
            return conn;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
            return null;
        }
    }

I visit many site but i can not solve it.Somebody share any link or guide me thanks.

Suraj Ali
  • 21
  • 7

1 Answers1

1

IMHO you still having the same problem I've stated in this answer: you are using sun.jdbc.odbc.JdbcOdbcDriver to connect to a MySQL database. This driver is intended to get a connection using JDBC-ODBC bridge, which is not the case here. Not to mention that was removed in JDK 8: Removal of JDBC ODBC bridge in java 8.

As I've stated you should not use DriverManager.getConnection() but DataSource.getConnection() instead. So in your MySqlConnect class (note Java Code Convention for class and methods names) make this change:

public class MySqlConnect {


    public static Connection connectToDB() {
        try {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setServerName("localhost");
            dataSource.setDatabaseName("auto_lube");
            dataSource.setPortNumber(3306);
            dataSource.setUser("root");
            dataSource.setPassword("mehar");

            Connection conn = dataSource.getConnection();
            JOptionPane.showMessageDialog(null, "Connection established"); // better log this message
            return conn;

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e); // better log the exception
            return null;
        }
    }
}

Of course, you have to include the right MySQL JDBC Connector in your project and stop using sun.jdbc.odbc.JdbcOdbcDriver

Community
  • 1
  • 1
dic19
  • 17,821
  • 6
  • 40
  • 69
  • bundle of thanks please tell me how i can directly contact with you on stack or any other source for sake of more guidance if you want? thanks again. – Suraj Ali Sep 08 '14 at 14:33
  • You are welcome. Please give it a try and if it works then [mark this answer as accepted](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). On the other hand it is better if you post questions here instead to contact a single person because: 1) You can be helped by lot of people (not just me). 2) Your questions can help other developers that have similar problems in the future. @SurajAli – dic19 Sep 08 '14 at 14:39
  • your answer is useful but after using i have same problem why? – Suraj Ali Sep 08 '14 at 14:48
  • Please edit your question including your updates and **full exception stack trace**. Nobody can guess what is happening now. @SurajAli – dic19 Sep 08 '14 at 14:51