Source Code Cross Referenced for HSQLEngine.java in  » Portal » DLOG4J » dlog4j » hsqldb » 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 » Portal » DLOG4J » dlog4j.hsqldb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  This program is free software; you can redistribute it and/or modify
003:         *  it under the terms of the GNU General Public License as published by
004:         *  the Free Software Foundation; either version 2 of the License, or
005:         *  (at your option) any later version.
006:         *
007:         *  This program is distributed in the hope that it will be useful,
008:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *  GNU Library General Public License for more details.
011:         *
012:         *  You should have received a copy of the GNU General Public License
013:         *  along with this program; if not, write to the Free Software
014:         *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015:         */
016:        package dlog4j.hsqldb;
017:
018:        import java.io.File;
019:        import java.sql.Connection;
020:        import java.sql.DriverManager;
021:        import java.sql.PreparedStatement;
022:        import java.sql.ResultSet;
023:
024:        import org.hsqldb.Server;
025:
026:        /**
027:         * HSQLDB数据库引擎管理器,用于启动和停止HSQLDB数据库服务
028:         * @author Winter Lau
029:         */
030:        public class HSQLEngine {
031:
032:            private static HSQLEngine engine;
033:            private static Server hsqldb;
034:
035:            private HSQLEngine() {
036:            }
037:
038:            /**
039:             * 获得一个数据库引擎的实例,需要一个数据路径的参数 
040:             * 该参数必须为物理存在的路径
041:             * @param dataPath
042:             * @param dbn 数据库名
043:             * @throws ClassNotFoundException
044:             * @throws NoSuchMethodException
045:             * @throws SecurityException
046:             */
047:            public synchronized static HSQLEngine getEngine(String dataPath,
048:                    int port, String dbn) {
049:                if (engine != null)
050:                    return engine;
051:                HSQLEngine engine = new HSQLEngine();
052:                if (!dataPath.endsWith(File.separator))
053:                    dataPath += File.separator;
054:                hsqldb = new Server();
055:                if (port > 0)
056:                    hsqldb.setPort(port);
057:                if (dbn != null) {
058:                    hsqldb.setDatabaseName(0, dbn);
059:                    dataPath += dbn;
060:                }
061:                hsqldb.setDatabasePath(0, dataPath);
062:
063:                hsqldb.setSilent(true);
064:                hsqldb.setTrace(false);
065:                return engine;
066:            }
067:
068:            public void start() {
069:                //调用HSQLDB的服务入口
070:                hsqldb.start();
071:            }
072:
073:            public void stop() {
074:                hsqldb.stop();
075:                int i = 0;
076:                while (i < 10 && isRunning()) {
077:                    i++;
078:                    try {
079:                        Thread.sleep(500);
080:                    } catch (Exception e) {
081:                    }
082:                }
083:            }
084:
085:            public boolean isRunning() {
086:                try {
087:                    hsqldb.checkRunning(true);
088:                    return true;
089:                } catch (RuntimeException e) {
090:                    return false;
091:                }
092:            }
093:
094:            public String getDatabaseName() {
095:                return hsqldb.getDatabaseName(0, false);
096:            }
097:
098:            public String getDataPath() {
099:                return hsqldb.getDatabasePath(0, false);
100:            }
101:
102:            public int getPort() {
103:                return hsqldb.getPort();
104:            }
105:
106:            public static void main(String[] args) throws Exception {
107:                HSQLEngine engine = HSQLEngine
108:                        .getEngine("D:\\TEST", 9001, null);
109:                engine.start();
110:                try {
111:                    testCreateTable();
112:                } finally {
113:                    engine.stop();
114:                }
115:            }
116:
117:            public static void testCreateTable() throws Exception {
118:                Class.forName("org.hsqldb.jdbcDriver");
119:                Connection conn = DriverManager.getConnection(
120:                        "jdbc:hsqldb:hsql://localhost", "sa", "");
121:                PreparedStatement ps = null;
122:                ResultSet rs = null;
123:                try {
124:                    //ps = conn.prepareStatement("create table dlog_bookmark (markid INTEGER,logid INTEGER,siteid INTEGER,userid INTEGER,marktype INTEGER,createTime DATE,markorder INTEGER);");
125:                    //ps.executeUpdate();
126:
127:                    ps = conn.prepareStatement("SELECT * FROM dlog_user");
128:                    rs = ps.executeQuery();
129:                    while (rs.next()) {
130:                        System.out.println(rs.getString("displayName"));
131:                    }
132:                } finally {
133:                    if (rs != null)
134:                        rs.close();
135:                    if (ps != null)
136:                        ps.close();
137:                    if (conn != null)
138:                        conn.close();
139:                }
140:            }
141:
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.