-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsertData.java
41 lines (32 loc) · 1.03 KB
/
InsertData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package my_jdbc;
import java.sql.Connection;
import java.util.Scanner;
import java.sql.Statement;
import java.sql.DriverManager;
public class InsertData implements Db {
public static void main(String[] args) {
try{
Class.forName(DRIVER);
Connection conn=DriverManager.getConnection(URl,USER,PWD);
Statement st = conn.createStatement();
Scanner sc =new Scanner(System.in);
System.out.println("enter name");
String name = sc.next();
System.out.println("enter salary");
float salary =sc.nextFloat();
System.out.println("enter desg");
String desg = sc.next();
sc.close();
//create query
String query ="insert into employee(name,salary,designation)values('"+name+"',"+salary+",'"+desg+"')";
int x = st.executeUpdate(query);// insert/update/delete
if(x>0){System.out.println("registration success");}
//close connection and statement
st.close();
conn.close();
}
catch(Exception e){
System.out.println("Registration failed:"+e);
}
}
}