Source Code Cross Referenced for DBUtils.java in  » Forum » mvnforum-1.1 » org » mvnforum » util » 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 » mvnforum 1.1 » org.mvnforum.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/util/DBUtils.java,v 1.6 2007/01/15 10:27:31 dungbtm Exp $
003:         * $Author: dungbtm $
004:         * $Revision: 1.6 $
005:         * $Date: 2007/01/15 10:27:31 $
006:         *
007:         * ====================================================================
008:         *
009:         * Copyright (C) 2002-2007 by MyVietnam.net
010:         *
011:         * All copyright notices regarding mvnForum MUST remain 
012:         * intact in the scripts and in the outputted HTML.
013:         * The "powered by" text/logo with a link back to
014:         * http://www.mvnForum.com and http://www.MyVietnam.net in 
015:         * the footer of the pages MUST remain visible when the pages
016:         * are viewed on the internet or intranet.
017:         *
018:         * This program is free software; you can redistribute it and/or modify
019:         * it under the terms of the GNU General Public License as published by
020:         * the Free Software Foundation; either version 2 of the License, or
021:         * any later version.
022:         *
023:         * This program is distributed in the hope that it will be useful,
024:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
025:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
026:         * GNU General Public License for more details.
027:         *
028:         * You should have received a copy of the GNU General Public License
029:         * along with this program; if not, write to the Free Software
030:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031:         *
032:         * Support can be obtained from support forums at:
033:         * http://www.mvnForum.com/mvnforum/index
034:         *
035:         * Correspondence and Marketing Questions can be sent to:
036:         * info at MyVietnam net
037:         *
038:         * @author: 
039:         */
040:        package org.mvnforum.util;
041:
042:        import java.io.File;
043:        import java.io.FileInputStream;
044:        import java.io.FileNotFoundException;
045:        import java.io.FileOutputStream;
046:        import java.io.IOException;
047:        import java.sql.Connection;
048:        import java.sql.DriverManager;
049:        import java.sql.ResultSet;
050:        import java.sql.SQLException;
051:        import java.sql.Statement;
052:
053:        import javax.xml.parsers.DocumentBuilder;
054:        import javax.xml.parsers.DocumentBuilderFactory;
055:        import javax.xml.parsers.ParserConfigurationException;
056:        import javax.xml.transform.Result;
057:        import javax.xml.transform.Source;
058:        import javax.xml.transform.Transformer;
059:        import javax.xml.transform.TransformerConfigurationException;
060:        import javax.xml.transform.TransformerException;
061:        import javax.xml.transform.TransformerFactory;
062:        import javax.xml.transform.dom.DOMSource;
063:        import javax.xml.transform.stream.StreamResult;
064:
065:        import org.w3c.dom.Document;
066:
067:        public class DBUtils {
068:
069:            private static Document doc = null;
070:
071:            static {
072:                try {
073:                    DocumentBuilder builder = DocumentBuilderFactory
074:                            .newInstance().newDocumentBuilder();
075:                    doc = builder.newDocument();
076:                    doc.appendChild(doc.createElement("MvnForum"));
077:                } catch (ParserConfigurationException e) {
078:                    e.printStackTrace();
079:                }
080:            }
081:
082:            /**
083:             * Get a connection from the connection pool. The returned connection
084:             * must be closed by calling DBUtils.closeConnection()
085:             * @return : a new connection from the pool if succeed
086:             * @throws SQLException : if cannot get a connection from the pool
087:             * @throws ClassNotFoundException 
088:             * @throws IOException 
089:             * @throws FileNotFoundException 
090:             */
091:            public static Connection getPhpbbConnection() throws SQLException {
092:
093:                String phpurl = "jdbc:mysql://" + Phpbb2MvnforumConfig.PHP_HOST
094:                        + "/" + Phpbb2MvnforumConfig.PHP_DB;
095:
096:                Connection conection = DriverManager.getConnection(phpurl,
097:                        Phpbb2MvnforumConfig.PHP_USER,
098:                        Phpbb2MvnforumConfig.PHP_PASS);
099:
100:                return conection;
101:            }
102:
103:            /**
104:             * Get a connection from the connection pool. The returned connection
105:             * must be closed by calling DBUtils.closeConnection()
106:             * @return : a new connection from the pool if succeed
107:             * @throws SQLException : if cannot get a connection from the pool
108:             * @throws ClassNotFoundException 
109:             * @throws IOException 
110:             * @throws FileNotFoundException 
111:             */
112:            public static Connection getMvnConnection() throws SQLException {
113:
114:                String phpurl = "jdbc:mysql://" + Phpbb2MvnforumConfig.MVN_HOST
115:                        + "/" + Phpbb2MvnforumConfig.MVN_DB;
116:
117:                Connection conection = DriverManager.getConnection(phpurl,
118:                        Phpbb2MvnforumConfig.MVN_USER,
119:                        Phpbb2MvnforumConfig.MVN_PASS);
120:
121:                return conection;
122:            }
123:
124:            /**
125:             * Use this method to close the ResultSet
126:             * @param rs : the resultset that needs to be closed
127:             */
128:            public static void closeResultSet(ResultSet rs) {
129:                if (rs != null) {
130:                    try {
131:                        rs.close();
132:                    } catch (SQLException e) {
133:                        e.printStackTrace();
134:                    }
135:                }
136:            }
137:
138:            /**
139:             * Use this method to close the Statement
140:             * @param statement : the statement that needs to be closed
141:             */
142:            public static void closeStatement(Statement statement) {
143:                if (statement != null) {
144:                    try {
145:                        statement.close();
146:                    } catch (SQLException e) {
147:                        e.printStackTrace();
148:                    }
149:                }
150:            }
151:
152:            /**
153:             * Use this method to return the connection to the connection pool
154:             * Do not use this method to close connection that is not from
155:             * the connection pool
156:             * @param connection : the connection that needs to be returned to the pool
157:             */
158:            public static void closeConnection(Connection connection) {
159:                if (connection != null) {
160:                    try {
161:                        connection.close();
162:                    } catch (SQLException e) {
163:                        e.printStackTrace();
164:                    }
165:                }
166:            }
167:
168:            public static Document getDomDocument() {
169:                return doc;
170:            }
171:
172:            public static void writeXmlFile(Document doc, String filename) {
173:                try {
174:                    // Prepare the DOM document for writing
175:                    Source source = new DOMSource(doc);
176:
177:                    // Prepare the output file
178:                    File file = new File(filename);
179:                    Result result = new StreamResult(file);
180:
181:                    // Write the DOM document to the file
182:                    Transformer xformer = TransformerFactory.newInstance()
183:                            .newTransformer();
184:                    xformer.transform(source, result);
185:                } catch (TransformerConfigurationException e) {
186:                    e.printStackTrace();
187:                } catch (TransformerException e) {
188:                    e.printStackTrace();
189:                }
190:            }
191:
192:            public static FileInputStream getInput() {
193:                try {
194:                    FileInputStream file = new FileInputStream(
195:                            Phpbb2MvnforumConfig.EXPORT_XML);
196:                    return file;
197:                } catch (FileNotFoundException e) {
198:                    e.printStackTrace();
199:                }
200:                return null;
201:            }
202:
203:            public static FileOutputStream getOutput() {
204:                try {
205:                    FileOutputStream file = new FileOutputStream(
206:                            Phpbb2MvnforumConfig.EXPORT_XML);
207:                    return file;
208:                } catch (FileNotFoundException e) {
209:                    e.printStackTrace();
210:                }
211:                return null;
212:            }
213:
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.