@@ -127,4 +127,138 @@ public NoticeVo getNoticeVo(int notice_num) {
127
127
finally { JdbcUtil .close (rs ); JdbcUtil .close (pstmt ); JdbcUtil .close (conn ); }
128
128
return noticeVo ;
129
129
}
130
+
131
+ public boolean noticeUpdate (NoticeVo noticeVo ) {
132
+ conn = JdbcUtil .getConnection ();
133
+ boolean success = false ;
134
+ String sql = "" ;
135
+
136
+ try {
137
+ sql = "UPDATE notice_board SET notice_category = ?, notice_author = ?, "
138
+ + "notice_title = ?, notice_content = ?, notice_date = sysdate "
139
+ + "WHERE notice_num = ?" ;
140
+ pstmt = conn .prepareStatement (sql );
141
+ pstmt .setString (1 , noticeVo .getNotice_category ());
142
+ pstmt .setString (2 , noticeVo .getNotice_author ());
143
+ pstmt .setString (3 , noticeVo .getNotice_title ());
144
+ pstmt .setString (4 , noticeVo .getNotice_content ());
145
+ pstmt .setInt (5 , noticeVo .getNotice_num ());
146
+ int result = pstmt .executeUpdate ();
147
+
148
+ if (result != 0 ) { success = true ; }
149
+ }
150
+ catch (SQLException e ) { e .printStackTrace (); }
151
+ finally { JdbcUtil .close (pstmt ); JdbcUtil .close (conn ); }
152
+ return success ;
153
+ }
154
+
155
+ public boolean noticeDelete (int notice_num ) {
156
+ conn = JdbcUtil .getConnection ();
157
+ boolean success = false ;
158
+ String sql = "" ;
159
+
160
+ try {
161
+ sql = "DELETE FROM notice_board WHERE notice_num = ?" ;
162
+ pstmt = conn .prepareStatement (sql );
163
+ pstmt .setInt (1 , notice_num );
164
+ int result = pstmt .executeUpdate ();
165
+
166
+ if (result != 0 ) { success = true ; }
167
+ }
168
+ catch (SQLException e ) { e .printStackTrace (); }
169
+ finally { JdbcUtil .close (pstmt ); JdbcUtil .close (conn ); }
170
+ return success ;
171
+ }
172
+
173
+ public ArrayList <NoticeVo > search (String searchName , String searchValue ) {
174
+ ArrayList <NoticeVo > noticeList = new ArrayList <>();
175
+
176
+ conn = JdbcUtil .getConnection ();
177
+ String sql = "" ;
178
+
179
+ try {
180
+ sql = "SELECT * FROM notice_board WHERE " ;
181
+ if (searchName .equals ("author" )) { sql += "notice_author LIKE ?" ; }
182
+ else { sql += "notice_title LIKE ?" ; }
183
+ sql += " ORDER BY notice_num DESC" ;
184
+ pstmt = conn .prepareStatement (sql );
185
+ pstmt .setString (1 , "%" + searchValue + "%" );
186
+ rs = pstmt .executeQuery ();
187
+
188
+ while (rs .next ()) {
189
+ NoticeVo noticeVo = new NoticeVo ();
190
+ noticeVo .setNotice_num (rs .getInt ("notice_num" ));
191
+ noticeVo .setNotice_category (rs .getString ("notice_category" ));
192
+ noticeVo .setNotice_author (rs .getString ("notice_author" ));
193
+ noticeVo .setNotice_title (rs .getString ("notice_title" ));
194
+ noticeVo .setNotice_content (rs .getString ("notice_content" ));
195
+ noticeVo .setNotice_date (rs .getTimestamp ("notice_date" ));
196
+ noticeList .add (noticeVo );
197
+ }
198
+ }
199
+ catch (SQLException e ) { e .printStackTrace (); }
200
+ finally { JdbcUtil .close (rs ); JdbcUtil .close (pstmt ); JdbcUtil .close (conn ); }
201
+ return noticeList ;
202
+ }
203
+
204
+ public int getSearchListCount (String searchName , String searchValue ) {
205
+ conn = JdbcUtil .getConnection ();
206
+ String sql = "" ;
207
+
208
+ int listCount = 0 ;
209
+
210
+ try {
211
+ sql = "SELECT COUNT(*) FROM notice_board WHERE " ;
212
+ if (searchName .equals ("author" )) { sql += "notice_author LIKE ?" ; }
213
+ else { sql += "notice_title LIKE ?" ; }
214
+ pstmt = conn .prepareStatement (sql );
215
+ pstmt .setString (1 , "%" + searchValue + "%" );
216
+ rs = pstmt .executeQuery ();
217
+
218
+ while (rs .next ()) { listCount = rs .getInt (1 ); }
219
+ }
220
+ catch (SQLException e ) { e .printStackTrace (); }
221
+ finally { JdbcUtil .close (rs ); JdbcUtil .close (pstmt ); JdbcUtil .close (conn ); }
222
+ return listCount ;
223
+ }
224
+
225
+ public ArrayList <NoticeVo > searchPage (String searchName , String searchValue , OraclePageMaker pageInfo ) {
226
+ ArrayList <NoticeVo > noticeList = new ArrayList <>();
227
+
228
+ conn = JdbcUtil .getConnection ();
229
+ String sql = "" ;
230
+
231
+ int startRow = pageInfo .getStartRow ();
232
+ int endRow = pageInfo .getEndRow ();
233
+
234
+ try {
235
+ sql += "SELECT * FROM " ;
236
+ sql += "(SELECT ROWNUM AS r, A.* FROM " ;
237
+ sql += "(SELECT ROWNUM AS rnum, TEMP.* FROM " ;
238
+ sql += "(SELECT * FROM notice_board WHERE " ;
239
+ if (searchName .equals ("author" )) { sql += "notice_author LIKE ?" ; }
240
+ else { sql += "notice_title LIKE ?" ; }
241
+ sql += " ORDER BY notice_num ASC) TEMP ORDER BY rnum DESC) A) WHERE r BETWEEN ? AND ?" ;
242
+ pstmt = conn .prepareStatement (sql );
243
+ pstmt .setString (1 , "%" + searchValue + "%" );
244
+ pstmt .setInt (2 , startRow );
245
+ pstmt .setInt (3 , endRow );
246
+ rs = pstmt .executeQuery ();
247
+
248
+ while (rs .next ()) {
249
+ NoticeVo noticeVo = new NoticeVo ();
250
+ noticeVo .setRnum (rs .getInt ("rnum" ));
251
+ noticeVo .setNotice_num (rs .getInt ("notice_num" ));
252
+ noticeVo .setNotice_category (rs .getString ("notice_category" ));
253
+ noticeVo .setNotice_author (rs .getString ("notice_author" ));
254
+ noticeVo .setNotice_title (rs .getString ("notice_title" ));
255
+ noticeVo .setNotice_content (rs .getString ("notice_content" ));
256
+ noticeVo .setNotice_date (rs .getTimestamp ("notice_date" ));
257
+ noticeList .add (noticeVo );
258
+ }
259
+ }
260
+ catch (SQLException e ) { e .printStackTrace (); }
261
+ finally { JdbcUtil .close (rs ); JdbcUtil .close (pstmt ); JdbcUtil .close (conn ); }
262
+ return noticeList ;
263
+ }
130
264
}
0 commit comments