Advertisement
adiee

jdbc

Apr 6th, 2022
1,432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package pr;
  2. import java.sql.*;
  3. import java.util.*;
  4.  
  5. public class employee  {
  6.  
  7.     public static void main(String[] args) throws SQLException {
  8.         try{
  9.             Class.forName("com.mysql.cj.jdbc.Driver");
  10.             PreparedStatement pst;
  11.             Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employedata","root","root");
  12.             System.out.println("Enter the id of the employee");
  13.             Scanner sc=new Scanner (System.in);
  14.             String id=sc.next();
  15.             System.out.println("Enter the name of the employe");
  16.            
  17.             String name=sc.next();
  18.             System.out.println("Enter the salary of the employe");
  19.             String salary=sc.next();
  20.            
  21.             String query="INSERT INTO 'employe_detail'(ID,employe name,salary)VALUES(?,?,?)";
  22.             pst=con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
  23.             pst.executeUpdate();
  24.             pst.setString(1, id);
  25.             pst.setString(2, name);
  26.             pst.setString(3, salary);
  27.            
  28.             pst.executeUpdate();
  29.            
  30.            
  31.                    
  32.         }
  33.         catch(ClassNotFoundException a){
  34.             a.printStackTrace();
  35.         }
  36.  
  37.     }
  38.  
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement