working with auto increment of mysql in JDBC For explanation Watch video :: code:: import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class AutoIncrementEx { private static final String query = "insert into emp2(ename,eadd) values(?,?)"; public static void main(String[] args) { try(Connection con = DriverManager.getConnection("jdbc:mysql:///new","root","root"); PreparedStatement ps = con.prepareStatement(query);){ ps.setString(1, "raja"); ps.setString(2, "nagpur"); int count = ps.executeUpdate(); if(count!=0) { System.out.println("Record Inserted"); }else { System.out.println("Record Not Inserted"); } }catch(SQLException se) { se.printStackTrace(); }catch(Exception e) { e.printStackTrace(); } } }