Skip to content
June 8, 2026
  • Privacy Policy
  • Terms & Conditions
  • Write For Us

Eduonix Blog

Learn and Build Your Skills

KS_Coding_6.0_696_90
Primary Menu
  • Privacy Policy
  • Terms & Conditions
  • Write For Us
  • Home
  • 2014
  • November
  • Learn to create sign up page along with database connectivity in java
  • Java Programming

Learn to create sign up page along with database connectivity in java

Tutor @ Eduonix November 30, 2014 7 minutes read
featured image

In this tutorial we will learn to create a sign up page along with database connectivity in java where we will be creating a new user sign up page and store its record into the database with the help of SQL statements similarly we can also view the table records with the help of respective SQL queries.

Steps for installation of MySQL Workbench :

    1. First of all, open up the browser.
    2. Open up Google search engine and enter the keyword as download MySQL Workbench in it.
    3. Select MySQL workbench version mysql-installer-community-5.6.21.0.msi.
    4. You will get below window

1

    1. Download it properly and save it in proper folder.
    2. Following window will get displayed.

img 2

    1. Double click on above MySQL setup and follow the default server setting.
    2. After installation completed, then click on the start menu and select MySQL.

 

    1. MySQL installation you can watch in the below view

img 3

    1. Click on the start menu, then select MySQL Workbench 6.1 CE then you will get the following screen.

img 4

    1. Now you can just double click on Local instance MySQL56 then you will see the below window.

img 5

    1. By clicking on the Local instance message dialog box window will get displayed, fill that window with password root and click on the OK button. Then you will get the following window.

img 6

    1. Now you create a new schema, just right click on MySQL windows left side then you will get two options.
      1. Create Schema.
      2. Refresh All.
    2. Click on Create Schema, you will get below the screen and give schema Name for that field and click on Apply button.

img 7

    1. Now you click on that schema which is created above window then that schema is expanded, you can see below screens left-hand side.

img 8

    1. Now right click on Table you get option Create Table Click on it, you will get below win.

img 9

    1. Fill up the required fields like Table Name, Column Name, Datatype (like varchar(50),int).
    2. Fill the options which are when you dealing with Id then Primary key, Auto increment, Not Null, etc is fill up properly as your requirement. After filling the all required fields click on the Apply button and then Finish button You will see the following screen.

img 10

    1. Check the table is created or not, using SQL Query on MySQL workbench.
       “select * from `demo’.’account`”;.

      Click on the Execute query button watch in the following window.

IMG 11

    1. You can see the output of that SQL query in the following screen

img 12

    1. Now your database and table are created successfully.

Now, let’s learn to connect JFrame and MySQL.
Now open Eclipse Create a new project.

        • Right-click on src create two new classes.
      1. Connectivity.java
      2. NewUser.java

Show in the below screen.

img 12

Example of Connection to MySQL database :

Example: Connectivity.java

//import statements
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Connectivity //create class Connectivity
{ 
		// JDBC driver name and database URL
		static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
		
	    static final String DB_URL = "jdbc:mysql://localhost/demo";

	    //  Database credentials
	    static final String USER = "root" ;
	    static final String PASS = "root";
	   
	    public static void main(String[] args) //main method
	    {
	    	Connection conn = null;//create object of Connection and define it null
	    	try //try block
	    	{
	    		//STEP 2: Register JDBC driver
	    		Class.forName("com.mysql.jdbc.Driver");
	    		//STEP 3: Open a connection
	    		System.out.println("Connecting to a selected database...");
	    		conn = DriverManager.getConnection(DB_URL, USER, PASS);
                        //print on console
	    		System.out.println("Connected database successfully...");	    	
                }
	    	catch(SQLException se) //catch block
	    	{
	    		//Handle errors for JDBC
	    		se.printStackTrace();
	    	}
	    	catch(Exception e) //catch block
	    	{
	    		//Handle errors for Class.forName
	    		e.printStackTrace();
	    	}
	    	finally  //finally block
	    	{
	    		//finally block used to close resources
	    		try  //try block
	    		{
	    			if(conn!=null)//condition
	    			conn.close(); //close connection
	    		}
	    		catch(SQLException se)//Handle errors
	    		{
	    			se.printStackTrace();
	    		}//end finally try
	    	}//end try
	    	System.out.println("Goodbye!"); //print on console
	    }//end main
}

Ultimate Java Development and Certification Course
Example: NewUser.java

//import statement
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Wrapper;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

public class NewUser extends JFrame //create class NewUser
{
	private JPanel contentPane; //declare variable
	private JTextField txtUser;
	private JButton btnSignup;
	private JTextField txtPassword;
	protected java.lang.String Spassword;
	
	// database URL
	static final String DB_URL = "jdbc:mysql://localhost/demo";
	
	//  Database credentials
	static final String USER = "root";
	static final String PASS = "root";
	protected static final String String = null;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) // main method
	{
		EventQueue.invokeLater(new Runnable() 
		{
			public void run() //define run method
			{
				try  //try block
				{
					//create NewUser frame object
					NewUser frame = new NewUser();
                                        //set NewUser frame visible
					frame.setVisible(true);
				} 
				catch (Exception e) //catch block
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public NewUser() //create constructor
	{	
		//set title
		setTitle("New User Login");
		//set close operation
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//set bounds of frame
		setBounds(100, 100, 450, 300);
		//create object of JPanel
		contentPane = new JPanel();
                //set contentPane border
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		set ContentPane with new object
		setContentPane(contentPane);
		set contentPane layout is null
		contentPane.setLayout(null);
		
                // create text field for user
		txtUser = new JTextField();
		//set bounds for text fields
		txtUser.setBounds(188, 51, 99, 20);
		//in contentPane add text field
		contentPane.add(txtUser);
		//set column for text field
		txtUser.setColumns(10);
		
		//lable the text field
		JLabel lblUserName = new JLabel("User Name");
		//set bounds for label
		lblUserName.setBounds(70, 54, 86, 14);
		//add into contentPane
		contentPane.add(lblUserName);
		
		//lable the text field
		JLabel lblPassword = new JLabel("Password");
		//set bounds for label
		lblPassword.setBounds(70, 109, 86, 14);
		//add into contentPane
		contentPane.add(lblPassword);
		
                //create button signup
		btnSignup = new JButton("SignUp");
		//add event handler on SignUp button
		btnSignup.addActionListener(new ActionListener() 
                {
		                public void actionPerformed(ActionEvent e) 
                                {				
				}
				//Create wrapper object and define it null
				Wrapper conn = null;
				try  //try block
                                {
                                //declare variables
				String username = "";
				String password = "";
				
				//get values using getText() method
				username = txtUser.getText().trim();
				password = txtPassword.getText().trim();
				
                                // check condition it field equals to blank throw error message
				if (username.equals("")|| password.equals(""))
				{
					JOptionPane.showMessageDialog(null," name or password or Role is wrong","Error",JOptionPane.ERROR_MESSAGE);
				}
				else  //else insert query is run properly
                                {
					String IQuery = "INSERT INTO `demo`.`loginaccount`(`username`,`password`,`ts`) VALUES('"+username+"', '"+password+"',current_timestamp)";
					System.out.println(IQuery);//print on console
					System.out.println("Connecting to a selected database...");
				
				//STEP 3: Open a connection
				conn = DriverManager.getConnection(DB_URL, USER, PASS);
					System.out.println("Connected database successfully...");
					  
				((Connection)conn).createStatement().execute(IQuery);//select the rows
					// define SMessage variable
					String SMessage = "Record added for "+username;
					
                                       // create dialog ox which is print message
	                    JOptionPane.showMessageDialog(null,SMessage,"Message",JOptionPane.PLAIN_MESSAGE);
					//close connection
					((java.sql.Connection)conn).close();
				}				
			}
			catch (SQLException se) 
			{
				//handle errors for JDBC
				se.printStackTrace();
			}
			catch (Exception a) //catch block
			{
				a.printStackTrace();
			}
		    }
		});
		//set bound for SignUp button
		btnSignup.setBounds(131, 165, 89, 23);
		//add button into contentPane
		contentPane.add(btnSignup);
		
		//create text field for password
		txtPassword = new JTextField();
		//set bound for password field
		txtPassword.setBounds(188, 106, 99, 20);
		//add text field on contentPane
		contentPane.add(txtPassword);
		set column for password text field
		txtPassword.setColumns(10);				
		}
}

Form :

img 14

Fill the form fields i.e. username and password and click on the SignUp button
After fill up all the fields when you click on the SignUp button JOptionPane message window will be displayed.

img 15

Now you check into MySQL database
Write SQL Query

select * from `demo`.`loginaccount`

Output :

img 16

Thus, we learned to create a sign-up page along with database connectivity in java where we have created a new user sign up page and stored its record into the database with the help of SQL statements and also viewed the table records with the help of respective SQL queries.

If you want to learn Database Design using MySQL then you can enroll with the “Learn Database Design with MySQL From Scratch“ online course. It provides over 30 lectures having around 9 hours of videos that will help you master Database Design and Data Storage for applications and websites using SQL & MySQL.

Read More: Learn about JDBC Connection with MySQL database

About the Author

Tutor @ Eduonix

Administrator

View All Posts

Post navigation

Previous: PHP Email
Next: PHP Filters

6 thoughts on “Learn to create sign up page along with database connectivity in java”

  1. james says:
    June 22, 2016 at 3:13 pm

    that’s good but what if you have many record how do you prevent many pop error messages such that it search first then denies access or accepts

    Reply
  2. Anjli Sharma says:
    July 10, 2016 at 8:39 am

    I want Program Of School Management along with add data,delete data,update data,login

    Reply
  3. poornesh says:
    February 19, 2017 at 6:23 am

    I AM GETING error in my program as Exception in thread “main” java.lang.Error: Unresolved compilation problem:

    at poornesh.Loginform.main(Loginform.java:37)

    Reply
    1. jaymel says:
      July 13, 2017 at 8:03 am

      We proposed for the employee college attendance system but the security of their pass, HOW ?

      Reply
  4. Bishwas says:
    January 3, 2018 at 1:37 pm

    I didn’t find mysql-installer-community-5.6.21.0.msi
    The link you showed is no more available

    Reply
  5. Ian Berry says:
    March 9, 2018 at 7:59 pm

    Some of the comments in the NewUser.java file are missing the // at the beginning.
    These are 73, 75 and 168.
    There are also problems with one too many } brackets.
    The fact that the file is only properly indented on some of the lines makes it difficult to identify where the brackets should be.
    I commented out the right bracket on line 108 //} on the assumption that you do want the following code to occur on actionPerformed and not leave it totally empty.

    Due to a missing serialVersionUID I added this on line 23
    private static final long serialVersionUID = 1L;

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Related Articles

Capture
  • Java Programming
  • Perl Programming
  • System Programming

Find Out Top 5 Computer Programming Scholarships to Apply for in 2023-2024

Tutor @ Eduonix August 23, 2023
Why Java Application Development is Necessary for Growing Businesses?
  • Business
  • Java Programming

Why Java Application Development is Necessary for Growing Businesses?

Tutor @ Eduonix October 13, 2021
JavaScript Programming - A Complete Guide for Beginners
  • Java Programming

JavaScript Programming – A Complete Guide For Beginners

Tutor @ Eduonix September 23, 2021
Copyright © Eduonix Learning Solutions. All rights reserved. | MoreNews by AF themes.