← Back to list

Mastering Java JDBC CRUD Operations in Eclipse Using MySQL

For Explanation watch video

idiot · 2026-05-22 13:44 · 0 claps · 1.3 min read paywalled
#jdbc #jdbc-driver #jdbc-connection #dbs
Open on Medium ↗

Mastering Java JDBC CRUD Operations in Eclipse Using MySQL

For Explanation watch video

[embed]

Insert Class

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class Insert {

    public static void main(String[] args) {

        //load the driver

        try {

            Class.forName("com.mysql.cj.jdbc.Driver");

        } catch (ClassNotFoundException e) {

            e.printStackTrace();

        }

        try (Connection con = DriverManager.getConnection("jdbc:mysql://@localhost:3306/new_schema", "root", "root"); Statement st = con.createStatement();) {

            String query = "INSERT INTO EMP(EID,ENAME) values(1,'Ram')";

            int count = st.executeUpdate(query);

            if (count == 0) {

                System.out.println("Record not inserted");

            } else {

                System.out.println("Record Inserted");

            }

        } catch (SQLException se) {

            se.printStackTrace();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}

Delete Class

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class Delete {

    public static void main(String[] args) {

        // load the driver

        try {

            Class.forName("com.mysql.cj.jdbc.Driver");

        } catch (ClassNotFoundException e) {

            e.printStackTrace();

        }

        try (Connection con = DriverManager.getConnection("jdbc:mysql://@localhost:3306/new_schema", "root", "root"); Statement st = con.createStatement();) {

            String query = "DELETE FROM EMP WHERE EID=1";

            int count = st.executeUpdate(query);

            if (count != 0) {

                System.out.println("Record Deleted");

            } else {

                System.out.println("Record Not Deleted");

            }

        } catch (SQLException se) {

            se.printStackTrace();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}

Update Class

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

public class Update {

    public static void main(String[] args) {

        // load the driver

        try {

            Class.forName("com.mysql.cj.jdbc.Driver");

        } catch (ClassNotFoundException e) {

            e.printStackTrace();

        }

        try (Connection con = DriverManager.getConnection("jdbc:mysql://@localhost:3306/new_schema", "root", "root"); Statement st = con.createStatement();) {

            String query = "UPDATE EMP SET ENAME='SAM' WHERE EID=1";

            int count = st.executeUpdate(query);

            if (count != 0) {

                System.out.println("Record UPDATED");

            } else {

                System.out.println("Record Not UPDATED");

            }

        } catch (SQLException se) {

            se.printStackTrace();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}

Select Class

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class Select {

    public static void main(String[] args) {

        // load the driver

        try {

            Class.forName("com.mysql.cj.jdbc.Driver");

        } catch (ClassNotFoundException e) {

            e.printStackTrace();

        }

        try (Connection con = DriverManager.getConnection("jdbc:mysql://@localhost:3306/new_schema", "root", "root"); Statement st = con.createStatement();) {

            String query = "SELECT EID,ENAME FROM EMP";

            ResultSet rs = st.executeQuery(query);

            while (rs.next()) {

                System.out.println(rs.getInt(1) + " " + rs.getString(2));

            }

        } catch (SQLException se) {

            se.printStackTrace();

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}

메타데이터
post_id
f80e4bdc00bc
slug
mastering-java-jdbc-crud-operations-in-eclipse-using-mysql-f80e4bdc00bc
url
https://medium.com/@idiotN/mastering-java-jdbc-crud-operations-in-eclipse-using-mysql-f80e4bdc00bc
canonical_url
https://medium.com/@idiotN/mastering-java-jdbc-crud-operations-in-eclipse-using-mysql-f80e4bdc00bc
author_url
https://medium.com/@idiotN
status
ok
fetched_at
2026-06-17 18:03:35