Java

Java JDBC Record Insertion into Mysql database

In this tutorial will teach jdbc record insertion into mysql database step by step.

java projectjava project

First Step

Establish the database Connection

Connection con;
    PreparedStatement pst;

     public void Connect()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver"); //Register the mysql driver
            con = DriverManager.getConnection("jdbc:mysql://localhost/phonebook","root","");
        } catch (ClassNotFoundException ex) {
           ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

Put the code inside the Save Button

try 
       {
            String friendname,phone,place;
            friendname = txtFname.getText();
            phone = txtphone.getText();
            place = txtplace.getText();
            pst = con.prepareStatement("insert into records(fname,phone,place)values(?,?,?)");
            pst.setString(1,friendname);
            pst.setString(2,phone);
            pst.setString(3,place);
            int status =  pst.executeUpdate();
            
            if(status==1)
            {
              JOptionPane.showMessageDialog(this, "Record Saved");  
                txtFname.setText("");
                txtphone.setText("");
                txtplace.setText("");
                txtFname.requestFocus();
            }
            else
            {
                 JOptionPane.showMessageDialog(this, "Record Failed");  
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

 

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Hotel Management System using Laravel 11

Relationships: Hotel ↔ Rooms (One-to-Many) A hotel can have many rooms, but a room belongs…

3 days ago

Creating Grocery Inventory App Using React

Introduction to Grocery Inventory Apps Managing grocery inventory can be a daunting task, but with…

1 week ago

Fish Inventory Shop Management System in Angular

This article explain how to make a Fish Inventory Management App in Angular.this app explain…

2 weeks ago

Fish Inventory Management with React

Introduction to Fish Inventory Management In the aquaculture industry, managing fish inventory is crucial for…

2 weeks ago

Java GUI CRUD for Beginners

Introduction to Java GUI CRUD Java is a powerful programming language widely used for building…

2 weeks ago

Creating Beautiful Login Form Design Using React

Introduction to Login Form Design Designing an effective and beautiful login form is crucial for…

3 weeks ago