-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertData.java
More file actions
39 lines (35 loc) · 1.1 KB
/
InsertData.java
File metadata and controls
39 lines (35 loc) · 1.1 KB
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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;
public class InsertData {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Class.forName("org.sqlite.JDBC");
Connection con=DriverManager.getConnection("jdbc:sqlite:product:db");
Scanner sc=new Scanner(System.in);
String sql="insert into movie values(?,?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
System.out.print("Enter your ID");
int id=sc.nextInt();
System.out.print("Enter Movie name ");
String mname=sc.next();
System.out.print("Lead Actor is");
String lac=sc.next();
System.out.print("Actress");
String act=sc.next();
System.out.print("Year of Direction");
int yr=sc.nextInt();
System.out.print("Director Name");
String dname=sc.next();
ps.setInt(1, id);
ps.setString(2, mname);
ps.setString(3, lac);
ps.setString(4, act);
ps.setInt(5, yr);
ps.setString(6, dname);
ps.executeUpdate();
System.out.print("Data Inserted");
sc.close();
}
}