-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroOp.java
More file actions
101 lines (91 loc) · 3.22 KB
/
Copy pathIntroOp.java
File metadata and controls
101 lines (91 loc) · 3.22 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.example.jdbc;
import ai.djl.util.Pair;
import com.example.basicLayout.Account;
import com.example.basicLayout.IntroObject;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import java.sql.*;
import java.util.ArrayList;
import java.util.Map;
public class IntroOp extends JdbcDaoSupport{
Connection con;
Statement stat;
ResultSet rs=null;
{
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/fin","root","123456");
stat=con.createStatement();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
public ArrayList<Pair<String,String>> getIntrosByType(int type){
try {
rs=stat.executeQuery("select * from introduction where `type`='"+type+"'");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
ArrayList<Pair<String,String>> id_name = new ArrayList<>();
while(true) {
try {
if (!rs.next()) break;
id_name.add(new Pair<String,String>(String.valueOf(rs.getInt(1)),rs.getString(2)));
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
return id_name;
}
public IntroObject getIntroById(String id){
try {
rs=stat.executeQuery("select * from introduction where `id`='"+id+"'");
} catch (SQLException throwables) {
throwables.printStackTrace();
}
while(true) {
try {
if (!rs.next()) break;
return new IntroObject(id, rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getInt(6), rs.getString(7));
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
return null;
}
public boolean createIntro(String name,String detail
,String img,String history,String type,String fromId){
try {
stat.execute("insert into introduction(" +
"`name`, `detail`, img, `history`, `type`, `fromId`)" +
" values ('"+name+"','"+detail
+"','"+img+"','"+history+"','"+type+"','"+fromId+"')");
return true;
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return false;
}
public boolean deleteIntro(String id){
try {
stat.execute("delete from introduction where `id` = "+id);
return true;
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return false;
}
public boolean modifyIntro(String id,String name,String detail
,String img,String history){
try {
String sql="update introduction set `name` = '"+name+"', `detail` = '"+detail+
"', `img` = '"+img+"', `history` = '"+history+
"' where `id` = '"+id+"'";
stat.execute(sql);
return true;
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return false;
}
public static void main(String[] args){
}
}