-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddProduct.java
More file actions
45 lines (36 loc) · 1.19 KB
/
AddProduct.java
File metadata and controls
45 lines (36 loc) · 1.19 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
40
41
42
43
44
45
package entities;
import java.util.Scanner;
import org.example.beans.Inventory;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class AddProduct {
public static void addProductDetails() {
/*
* Configuration and SessionFactory is responsible for create the table
*/
Inventory st = new Inventory();
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
System.out.println("Enter Product Name");
String name = sc.nextLine();
System.out.println("Enter Product Type");
String type = sc.nextLine();
System.out.println("Enter Product Quantity");
int quantity= sc.nextInt();
sc.nextLine();
System.out.println("Enter Product Price");
int price= sc.nextInt();
sc.nextLine();
Configuration cfg = new Configuration();
cfg.configure("resources/hibernate.cfg.xml");
SessionFactory sf = cfg.buildSessionFactory();
Session s = sf.openSession();
st.setName(name);
st.setType(type);
st.setQuantity(quantity);
st.setPrice(price);
s.save(st);
s.beginTransaction().commit();
}
}