-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDeleteDb.java
More file actions
56 lines (47 loc) · 1.45 KB
/
DeleteDb.java
File metadata and controls
56 lines (47 loc) · 1.45 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
46
47
48
49
50
51
52
53
54
55
56
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Admin
*/
class DeleteDb {
Statement st;
int deleteItem(String product_id) {
connectToDb();
String deletequery="DELETE FROM product WHERE itemid="+product_id+" ";
try {
int a=st.executeUpdate(deletequery);
if(a==1)
{
return a;
}
else
{
return a;
}
} catch (SQLException ex) {
Logger.getLogger(DeleteDb.class.getName()).log(Level.SEVERE, null, ex);
}
return 0;
}
private void connectToDb() {
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/productdb";
try {
Class.forName(driver);
Connection con=DriverManager.getConnection(url,"root","");
st=con.createStatement();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DeleteDb.class.getName()).log(Level.SEVERE, null, ex);
}
}
}