Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pr;
- import java.sql.*;
- import java.util.*;
- public class employee {
- public static void main(String[] args) throws SQLException {
- try{
- Class.forName("com.mysql.cj.jdbc.Driver");
- PreparedStatement pst;
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employedata","root","root");
- System.out.println("Enter the id of the employee");
- Scanner sc=new Scanner (System.in);
- String id=sc.next();
- System.out.println("Enter the name of the employe");
- String name=sc.next();
- System.out.println("Enter the salary of the employe");
- String salary=sc.next();
- String query="INSERT INTO 'employe_detail'(ID,employe name,salary)VALUES(?,?,?)";
- pst=con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
- pst.executeUpdate();
- pst.setString(1, id);
- pst.setString(2, name);
- pst.setString(3, salary);
- pst.executeUpdate();
- }
- catch(ClassNotFoundException a){
- a.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement