Source Code Cross Referenced for Utilities.java in  » Forum » JsForum » forum » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Forum » JsForum » forum 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package forum;
002:
003:        import javax.servlet.*;
004:        import javax.servlet.http.*;
005:        import java.sql.*;
006:        import java.sql.Connection;
007:        import java.sql.Statement;
008:        import java.sql.ResultSet;
009:
010:        public class Utilities {
011:
012:            public static String getTopics(String forum_id) {
013:
014:                String topics = null;
015:                try {
016:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
017:                            .getDbLogin(), Variable.getDbPassword());
018:                    db.connect();
019:
020:                    ResultSet rs = db
021:                            .selectQuery("SELECT count(*) topics FROM forum_message "
022:                                    + "WHERE forum_id =\""
023:                                    + forum_id
024:                                    + "\" "
025:                                    + "AND reply_id=\"0\"");
026:
027:                    while (rs.next()) {
028:                        topics = rs.getString("topics");
029:                    }
030:                    db.close();
031:                } catch (Exception e) {
032:                }
033:
034:                return topics;
035:            }
036:
037:            public static String getforumReplies(String forum_id) {
038:
039:                String replies = null;
040:                try {
041:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
042:                            .getDbLogin(), Variable.getDbPassword());
043:                    db.connect();
044:
045:                    ResultSet rs = db.selectQuery("SELECT count(*)-"
046:                            + getTopics(forum_id)
047:                            + " replies FROM forum_message "
048:                            + "WHERE forum_id =\"" + forum_id + "\"");
049:
050:                    while (rs.next()) {
051:                        replies = rs.getString("replies");
052:                    }
053:                    db.close();
054:                } catch (Exception e) {
055:                }
056:
057:                return replies;
058:            }
059:
060:            public static String getReplies(String forum_id, String thread_id) {
061:
062:                String replies = null;
063:                try {
064:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
065:                            .getDbLogin(), Variable.getDbPassword());
066:                    db.connect();
067:
068:                    ResultSet rs = db
069:                            .selectQuery("SELECT count(*)-1 replies FROM forum_message "
070:                                    + "WHERE forum_id=\""
071:                                    + forum_id
072:                                    + "\" AND thread_id =\"" + thread_id + "\"");
073:
074:                    while (rs.next()) {
075:                        replies = rs.getString("replies");
076:                    }
077:                    db.close();
078:                } catch (Exception e) {
079:                }
080:
081:                return replies;
082:            }
083:
084:            public static String getMorePages(String replies, String forum_id,
085:                    String thread_id, boolean pages) {
086:
087:                String morePages = "";
088:                if (!((Integer.parseInt(replies) + 1) < (Integer
089:                        .parseInt(Variable.getMessagePerPage()) + 1))) {
090:
091:                    if (pages) {
092:                        morePages += "&nbsp;( ";
093:                    }
094:
095:                    for (int i = 0; i < (Integer.parseInt(replies) + 1); i += (Integer
096:                            .parseInt(Variable.getMessagePerPage()))) {
097:                        morePages += "<a href=message.jsp?forum_id="
098:                                + forum_id
099:                                + "&thread_id="
100:                                + thread_id
101:                                + "&start="
102:                                + i
103:                                + " class=\"pathBarLink\">"
104:                                + ((i / (Integer.parseInt(Variable
105:                                        .getMessagePerPage()))) + 1) + "</a> ";
106:                    }
107:                    if (pages) {
108:                        morePages += " )</span>";
109:                    }
110:                }
111:                return morePages;
112:            }
113:
114:            public static String getforumTile(String forum_id) {
115:
116:                String forumTitle = null;
117:                try {
118:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
119:                            .getDbLogin(), Variable.getDbPassword());
120:                    db.connect();
121:
122:                    ResultSet rs = db
123:                            .selectQuery("SELECT title FROM forum_forums "
124:                                    + "WHERE forum_id=\"" + forum_id + "\"");
125:
126:                    while (rs.next()) {
127:                        forumTitle = rs.getString("title");
128:                    }
129:                    db.close();
130:                } catch (Exception e) {
131:                }
132:
133:                return forumTitle;
134:            }
135:
136:            public static String getThreadTile(String forum_id, String thread_id) {
137:
138:                String threadTitle = null;
139:                try {
140:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
141:                            .getDbLogin(), Variable.getDbPassword());
142:                    db.connect();
143:
144:                    ResultSet rs = db
145:                            .selectQuery("SELECT title FROM forum_threads "
146:                                    + "WHERE forum_id=\"" + forum_id + "\" "
147:                                    + "AND thread_id=\"" + thread_id + "\"");
148:
149:                    while (rs.next()) {
150:                        threadTitle = rs.getString("title");
151:                    }
152:                    db.close();
153:                } catch (Exception e) {
154:                }
155:
156:                return threadTitle;
157:            }
158:
159:            public static String getforumInfo(String forum_id) {
160:
161:                String forumInfo = null;
162:                try {
163:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
164:                            .getDbLogin(), Variable.getDbPassword());
165:                    db.connect();
166:
167:                    ResultSet rs = db
168:                            .selectQuery("SELECT forum_info FROM forum_forums "
169:                                    + "WHERE forum_id=\"" + forum_id + "\"");
170:
171:                    while (rs.next()) {
172:                        forumInfo = rs.getString("forum_info");
173:                    }
174:                    db.close();
175:                } catch (Exception e) {
176:                }
177:
178:                if (forumInfo.equals(null)) {
179:                    forumInfo = "";
180:                }
181:
182:                return forumInfo;
183:            }
184:
185:            public static String lastPostInfo(String forum_id) {
186:
187:                String lastPostInfo = null;
188:                String thread_id = null;
189:                String title = null;
190:                String date_time = null;
191:                String user = null;
192:
193:                try {
194:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
195:                            .getDbLogin(), Variable.getDbPassword());
196:                    db.connect();
197:
198:                    ResultSet rs = db
199:                            .selectQuery("SELECT MAX(date_time) date_time FROM forum_message "
200:                                    + "WHERE forum_id=\"" + forum_id + "\"");
201:
202:                    while (rs.next()) {
203:                        date_time = rs.getString("date_time");
204:                    }
205:
206:                    ResultSet rs2 = db
207:                            .selectQuery("SELECT thread_id,user FROM forum_message "
208:                                    + "WHERE forum_id=\""
209:                                    + forum_id
210:                                    + "\" "
211:                                    + "AND date_time=\"" + date_time + "\"");
212:
213:                    while (rs2.next()) {
214:                        thread_id = rs2.getString("thread_id");
215:                        user = rs2.getString("user");
216:                    }
217:
218:                    ResultSet rs3 = db
219:                            .selectQuery("SELECT * FROM forum_threads "
220:                                    + "WHERE thread_id=\"" + thread_id + "\" "
221:                                    + "AND forum_id=\"" + forum_id + "\"");
222:
223:                    while (rs3.next()) {
224:                        title = rs3.getString("title");
225:                    }
226:
227:                    if (date_time == null) {
228:                        date_time = "No info";
229:                    }
230:                    if (user == null) {
231:                        user = "No info";
232:                    }
233:                    if (title == null) {
234:                        title = "No info";
235:                    }
236:
237:                    lastPostInfo = date_time + "<br>In: " + title + "<br>By: "
238:                            + user;
239:
240:                    db.close();
241:                } catch (Exception e) {
242:                }
243:
244:                return lastPostInfo;
245:            }
246:
247:            public static String lastActionInfo(String forum_id,
248:                    String thread_id) {
249:
250:                String lastPostInfo = null;
251:                String date_time = null;
252:                String user = null;
253:
254:                try {
255:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
256:                            .getDbLogin(), Variable.getDbPassword());
257:                    db.connect();
258:
259:                    ResultSet rs = db
260:                            .selectQuery("SELECT MAX(date_time) date_time FROM forum_message "
261:                                    + "WHERE forum_id=\""
262:                                    + forum_id
263:                                    + "\" "
264:                                    + "AND thread_id=\"" + thread_id + "\"");
265:
266:                    while (rs.next()) {
267:                        date_time = rs.getString("date_time");
268:                    }
269:
270:                    ResultSet rs2 = db
271:                            .selectQuery("SELECT user FROM forum_message "
272:                                    + "WHERE forum_id=\"" + forum_id + "\" "
273:                                    + "AND thread_id=\"" + thread_id + "\" "
274:                                    + "AND date_time=\"" + date_time + "\"");
275:
276:                    while (rs2.next()) {
277:                        user = rs2.getString("user");
278:                    }
279:
280:                    if (date_time == null) {
281:                        date_time = "No info";
282:                    }
283:                    if (user == null) {
284:                        user = "No info";
285:                    }
286:
287:                    lastPostInfo = date_time + "<br>Last post by: " + user;
288:
289:                    db.close();
290:                } catch (Exception e) {
291:                }
292:
293:                return lastPostInfo;
294:            }
295:
296:            public static void addView(String forum_id, String thread_id) {
297:
298:                try {
299:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
300:                            .getDbLogin(), Variable.getDbPassword());
301:                    db.connect();
302:
303:                    db.query("UPDATE forum_threads SET views = views + 1 "
304:                            + "WHERE forum_id =\"" + forum_id + "\" "
305:                            + "AND thread_id=\"" + thread_id + "\"");
306:
307:                    db.close();
308:                } catch (Exception e) {
309:                }
310:            }
311:
312:            public static String getViews(String forum_id, String thread_id) {
313:
314:                String views = null;
315:                try {
316:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
317:                            .getDbLogin(), Variable.getDbPassword());
318:                    db.connect();
319:
320:                    ResultSet rs = db
321:                            .selectQuery("SELECT views FROM forum_threads "
322:                                    + "WHERE forum_id=\"" + forum_id + "\" "
323:                                    + "AND thread_id=\"" + thread_id + "\"");
324:
325:                    while (rs.next()) {
326:                        views = rs.getString("views");
327:                    }
328:                    db.close();
329:                } catch (Exception e) {
330:                }
331:
332:                return views;
333:            }
334:
335:            public static int getMessageLength(String forum_id,
336:                    String thread_id, String reply_id) {
337:                int messageLength = 0;
338:                try {
339:                    DBConnectie db = new DBConnectie(Variable.getDb(), Variable
340:                            .getDbLogin(), Variable.getDbPassword());
341:                    db.connect();
342:
343:                    ResultSet rs = db
344:                            .selectQuery("SELECT message FROM forum_message "
345:                                    + "WHERE forum_id=\"" + forum_id + "\" "
346:                                    + "AND thread_id=\"" + thread_id + "\" "
347:                                    + "AND reply_id=\"" + reply_id + "\"");
348:
349:                    while (rs.next()) {
350:                        messageLength = rs.getString("message").length();
351:                    }
352:                    db.close();
353:                } catch (Exception e) {
354:                }
355:
356:                return messageLength;
357:
358:            }
359:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.