File tree 3 files changed +67
-1
lines changed 3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 54
54
.equalsTo(123456))
55
55
.create();
56
56
57
+ String delete1 = new SQLDelete()
58
+ .fromTable("manuscript")
59
+ .where(new SQLCondition()
60
+ .whereAttribute("author_id")
61
+ .equalsTo("123456"))
62
+ .create();
63
+
57
64
stmt.executeQuery(new SQLQuery()
58
65
.select('*')
59
66
.from("manuscript")
Original file line number Diff line number Diff line change
1
+ package com .tpwang .sql ;
2
+
3
+ public class SQLDelete {
4
+
5
+ private StringBuilder builder = null ;
6
+
7
+ /***
8
+ * Constructor
9
+ */
10
+ public SQLDelete () {
11
+ builder = new StringBuilder ().append ("DELETE " );
12
+ }
13
+
14
+ /***
15
+ * Where to delete from
16
+ * @param tableName Delete table name
17
+ * @return delete
18
+ */
19
+ public SQLDelete fromTable (String tableName ) {
20
+ builder .append ("FROM " ).append (tableName ).append (' ' );
21
+ return this ;
22
+ }
23
+
24
+ /***
25
+ * How to delete
26
+ * @param condition Delete condition
27
+ * @return delete
28
+ */
29
+ public SQLDelete where (SQLCondition condition ) {
30
+ builder .append (condition .toString ());
31
+ return this ;
32
+ }
33
+
34
+ /***
35
+ * How to delete
36
+ * @param condition Delete condition
37
+ * @return delete
38
+ */
39
+ public SQLDelete where (String condition ) {
40
+ builder .append (condition );
41
+ return this ;
42
+ }
43
+
44
+ /***
45
+ * Return the final query
46
+ * @return delete string
47
+ */
48
+ public String create () {
49
+ return toString ();
50
+ }
51
+
52
+ /***
53
+ * Return the final query
54
+ */
55
+ @ Override
56
+ public String toString () {
57
+ return builder .toString ().trim ();
58
+ }
59
+ }
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ public String create() {
119
119
public String toString () {
120
120
return builder .append ("SET " ).append (joiner .toString ()).append (' ' )
121
121
.append ("WHERE " ).append (condition )
122
- .toString ();
122
+ .toString (). trim () ;
123
123
}
124
124
125
125
}
You can’t perform that action at this time.
0 commit comments