Create logging window using Java and MySql

In most cases most of database projects have the logging window. In here we will see how to create a simple but important logging window using java and MySQL. I have created a database called testlogging and inside the database I have created a table called it logging. And there are two rows one field store the usernames and other field stores the password of the user. U can create your own database and just you want to replace the data fields of my code. OK enjoy it budy…



here is the connection class.

package logging;

import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;

 * @author Developer
public class connection {

    public Connection creatConnection () throws ClassNotFoundException
           Connection conn=null;

            Class.forName("com.mysql.jdbc.Driver").newInstance();//call jdbc driver
            String url = "jdbc:mysql://localhost/testlogging";//getting url
            conn = DriverManager.getConnection(url,"root","1234");//create connection

        catch (Exception e)
         // JOptionPane.showMessageDialog(null,"Error occured!.."+ e.getLocalizedMessage());
          JOptionPane.showMessageDialog(null, e.getMessage(), "Ooops",JOptionPane.ERROR_MESSAGE, null);//exeption hanling

        return conn;//return connection to all


This the logging validation method from MySql database.

private void btnSignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSignActionPerformed

        connection getcon = new connection();
        Connection conn;

            conn=getcon.creatConnection();//getting connection

            //execute query

             ResultSet rs = conn.createStatement().executeQuery("select * from logging where username='"  + txtusername.getText().trim() + "'and password='" + txtpassword.getText().trim() + "' ");

             if({ // if the requested results are avialble

             JOptionPane.showMessageDialog(rootPane, "Logging successfull...");
             // display the message


                 JOptionPane.showMessageDialog(null, "Username or password incorrect..Please enter correct details..");

                 txtpassword.setText(null); // if the wrong answer clear the text fields

        catch(Exception ex)
            JOptionPane.showMessageDialog(rootPane, ex);

        // TODO add your handling code here:

Download the project from here

I have inserted the .sql file inside the .rar file and you want to install MySql Gui tools to restore it

2 thoughts on “Create logging window using Java and MySql

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.