Source Code Cross Referenced for EnrollerBean.java in  » IDE-Netbeans » usersguide » enroller » 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 » IDE Netbeans » usersguide » enroller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2005 Sun Microsystems, Inc.  All rights reserved.  U.S.
003:         * Government Rights - Commercial software.  Government users are subject
004:         * to the Sun Microsystems, Inc. standard license agreement and
005:         * applicable provisions of the FAR and its supplements.  Use is subject
006:         * to license terms.
007:         *
008:         * This distribution may include materials developed by third parties.
009:         * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
010:         * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
011:         * other countries.
012:         *
013:         * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
014:         *
015:         * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
016:         * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
017:         * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
018:         * en vigueur de la FAR (Federal Acquisition Regulations) et des
019:         * supplements a celles-ci.  Distribue par des licences qui en
020:         * restreignent l'utilisation.
021:         *
022:         * Cette distribution peut comprendre des composants developpes par des
023:         * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
024:         * sont des marques de fabrique ou des marques deposees de Sun
025:         * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
026:         */
027:
028:        package enroller;
029:
030:        import java.rmi.RemoteException;
031:        import javax.ejb.*;
032:        import java.sql.*;
033:        import javax.sql.*;
034:        import java.util.*;
035:        import javax.naming.*;
036:
037:        public class EnrollerBean implements  SessionBean,
038:                EnrollerRemoteBusiness {
039:            private static final String dbName = "jdbc/pointbase";
040:            private Connection con;
041:            private SessionContext context;
042:
043:            public EnrollerBean() {
044:            }
045:
046:            public void enroll(String studentId, String courseId) {
047:                try {
048:                    insertEntry(studentId, courseId);
049:                } catch (Exception ex) {
050:                    throw new EJBException("enroll: " + ex.getMessage());
051:                }
052:            }
053:
054:            public void unEnroll(String studentId, String courseId) {
055:                try {
056:                    deleteEntry(studentId, courseId);
057:                } catch (Exception ex) {
058:                    throw new EJBException("unEnroll: " + ex.getMessage());
059:                }
060:            }
061:
062:            public void deleteStudent(String studentId) {
063:                try {
064:                    deleteStudentEntries(studentId);
065:                } catch (Exception ex) {
066:                    throw new EJBException("deleteStudent: " + ex.getMessage());
067:                }
068:            }
069:
070:            public void deleteCourse(String courseId) {
071:                try {
072:                    deleteCourseEntries(courseId);
073:                } catch (Exception ex) {
074:                    throw new EJBException("deleteCourse: " + ex.getMessage());
075:                }
076:            }
077:
078:            public ArrayList getStudentIds(String courseId) {
079:                try {
080:                    return selectStudent(courseId);
081:                } catch (Exception ex) {
082:                    throw new EJBException("getStudentIds: " + ex.getMessage());
083:                }
084:            }
085:
086:            public ArrayList getCourseIds(String studentId) {
087:                try {
088:                    return selectCourse(studentId);
089:                } catch (Exception ex) {
090:                    throw new EJBException("getCourseIds: " + ex.getMessage());
091:                }
092:            }
093:
094:            public void ejbCreate() {
095:            }
096:
097:            public void ejbRemove() {
098:            }
099:
100:            public void ejbActivate() {
101:            }
102:
103:            public void ejbPassivate() {
104:            }
105:
106:            public void setSessionContext(SessionContext context) {
107:                this .context = context;
108:            }
109:
110:            /*********************** Database Routines *************************/
111:            private void makeConnection() {
112:                try {
113:                    InitialContext ic = new InitialContext();
114:                    DataSource ds = (DataSource) ic.lookup(dbName);
115:
116:                    con = ds.getConnection();
117:                } catch (Exception ex) {
118:                    throw new EJBException("Unable to connect to database. "
119:                            + ex.getMessage());
120:                }
121:            }
122:
123:            private void releaseConnection() {
124:                try {
125:                    con.close();
126:                } catch (SQLException ex) {
127:                    throw new EJBException("releaseConnection: "
128:                            + ex.getMessage());
129:                }
130:            }
131:
132:            private void insertEntry(String studentId, String courseId)
133:                    throws SQLException {
134:                makeConnection();
135:
136:                String insertStatement = "insert into enrollment values ( ? , ? )";
137:                PreparedStatement prepStmt = con
138:                        .prepareStatement(insertStatement);
139:
140:                prepStmt.setString(1, studentId);
141:                prepStmt.setString(2, courseId);
142:
143:                prepStmt.executeUpdate();
144:                prepStmt.close();
145:                releaseConnection();
146:            }
147:
148:            private void deleteEntry(String studentId, String courseId)
149:                    throws SQLException {
150:                makeConnection();
151:
152:                String deleteStatement = "delete from enrollment "
153:                        + "where studentid = ? and courseid = ?";
154:                PreparedStatement prepStmt = con
155:                        .prepareStatement(deleteStatement);
156:
157:                prepStmt.setString(1, studentId);
158:                prepStmt.setString(2, courseId);
159:                prepStmt.executeUpdate();
160:                prepStmt.close();
161:                releaseConnection();
162:            }
163:
164:            private void deleteStudentEntries(String studentId)
165:                    throws SQLException {
166:                makeConnection();
167:
168:                String deleteStatement = "delete from enrollment "
169:                        + "where studentid = ?";
170:                PreparedStatement prepStmt = con
171:                        .prepareStatement(deleteStatement);
172:
173:                prepStmt.setString(1, studentId);
174:                prepStmt.executeUpdate();
175:                prepStmt.close();
176:                releaseConnection();
177:            }
178:
179:            private void deleteCourseEntries(String courseId)
180:                    throws SQLException {
181:                makeConnection();
182:
183:                String deleteStatement = "delete from enrollment "
184:                        + "where courseid = ?";
185:                PreparedStatement prepStmt = con
186:                        .prepareStatement(deleteStatement);
187:
188:                prepStmt.setString(1, courseId);
189:                prepStmt.executeUpdate();
190:                prepStmt.close();
191:                releaseConnection();
192:            }
193:
194:            private ArrayList selectStudent(String courseId)
195:                    throws SQLException {
196:                makeConnection();
197:
198:                String selectStatement = "select studentid "
199:                        + "from enrollment where courseid = ? ";
200:                PreparedStatement prepStmt = con
201:                        .prepareStatement(selectStatement);
202:
203:                prepStmt.setString(1, courseId);
204:
205:                ResultSet rs = prepStmt.executeQuery();
206:                ArrayList a = new ArrayList();
207:
208:                while (rs.next()) {
209:                    String id = rs.getString(1);
210:
211:                    a.add(id);
212:                }
213:
214:                prepStmt.close();
215:                releaseConnection();
216:
217:                return a;
218:            }
219:
220:            private ArrayList selectCourse(String studentId)
221:                    throws SQLException {
222:                makeConnection();
223:
224:                String selectStatement = "select courseid "
225:                        + "from enrollment where studentid = ? ";
226:                PreparedStatement prepStmt = con
227:                        .prepareStatement(selectStatement);
228:
229:                prepStmt.setString(1, studentId);
230:
231:                ResultSet rs = prepStmt.executeQuery();
232:                ArrayList a = new ArrayList();
233:
234:                while (rs.next()) {
235:                    String id = rs.getString(1);
236:
237:                    a.add(id);
238:                }
239:
240:                prepStmt.close();
241:                releaseConnection();
242:
243:                return a;
244:            }
245:        }
246:        // EnrollerBean
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.