- 浏览: 722983 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
一剪梅:
关于您对于 hasRolePermission 用法的解释, ...
OFBIZ安全性技术(翻译) -
沈寅麟:
数据模型资源手册卷3中文版出版了 -
donaldjohn:
恭喜恭喜, 预祝大卖
数据模型资源手册卷3中文版出版了 -
成大大的:
OFBiz电商实战百度网盘下载:http://pan.baid ...
OFBiz入门实训教程 -
成大大的:
OFBiz电商实战百度网盘下载:http://pan.baid ...
OFBiz促销码生成解释
hsqldb自带的例子。看看就一切ok了,万事不求人啊。
There is a copy of Testdb.java in the directory src/org/hsqldb/sample of your HSQLDB distribution.
There is a copy of Testdb.java in the directory src/org/hsqldb/sample of your HSQLDB distribution.
java 代码
- 1. /* Copyright (c) 2001-2005, The HSQL Development Group
- 2. * All rights reserved.
- 3. *
- 4. * Redistribution and use in source and binary forms, with or without
- 5. * modification, are permitted provided that the following conditions are met:
- 6. *
- 7. * Redistributions of source code must retain the above copyright notice, this
- 8. * list of conditions and the following disclaimer.
- 9. *
- 10. * Redistributions in binary form must reproduce the above copyright notice,
- 11. * this list of conditions and the following disclaimer in the documentation
- 12. * and/or other materials provided with the distribution.
- 13. *
- 14. * Neither the name of the HSQL Development Group nor the names of its
- 15. * contributors may be used to endorse or promote products derived from this
- 16. * software without specific prior written permission.
- 17. *
- 18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- 19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- 20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- 21. * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
- 22. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- 23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- 24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- 25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- 26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- 27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- 28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- 29. */
ruby 代码
- package org.hsqldb.sample;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- * Title: Testdb
- * Description: simple hello world db example of a
- * standalone persistent db application
- *
- * every time it runs it adds four more rows to sample_table
- * it does a query and prints the results to standard out
- *
- * Author: Karl Meissner karl@meissnersd.com
- */
- public class Testdb {
- Connection conn; //our connnection to the db - presist for life of program
- // we dont want this garbage collected until we are done
- public Testdb(String db_file_name_prefix) throws Exception { // note more general exception
- // Load the HSQL Database Engine JDBC driver
- // hsqldb.jar should be in the class path or made part of the current jar
- Class.forName("org.hsqldb.jdbcDriver");
- // connect to the database. This will load the db files and start the
- // database if it is not alread running.
- // db_file_name_prefix is used to open or create files that hold the state
- // of the db.
- // It can contain directory names relative to the
- // current working directory
- conn = DriverManager.getConnection("jdbc:hsqldb:"
- + db_file_name_prefix, // filenames
- "sa", // username
- ""); // password
- }
- public void shutdown() throws SQLException {
- Statement st = conn.createStatement();
- // db writes out to files and performs clean shuts down
- // otherwise there will be an unclean shutdown
- // when program ends
- st.execute("SHUTDOWN");
- conn.close(); // if there are no other open connection
- }
- //use for SQL command SELECT
- public synchronized void query(String expression) throws SQLException {
- Statement st = null;
- ResultSet rs = null;
- st = conn.createStatement(); // statement objects can be reused with
- // repeated calls to execute but we
- // choose to make a new one each time
- rs = st.executeQuery(expression); // run the query
- // do something with the result set.
- dump(rs);
- st.close(); // NOTE!! if you close a statement the associated ResultSet is
- // closed too
- // so you should copy the contents to some other object.
- // the result set is invalidated also if you recycle an Statement
- // and try to execute some other query before the result set has been
- // completely examined.
- }
- //use for SQL commands CREATE, DROP, INSERT and UPDATE
- public synchronized void update(String expression) throws SQLException {
- Statement st = null;
- st = conn.createStatement(); // statements
- int i = st.executeUpdate(expression); // run the query
- if (i == -1) {
- System.out.println("db error : " + expression);
- }
- st.close();
- } // void update()
- public static void dump(ResultSet rs) throws SQLException {
- // the order of the rows in a cursor
- // are implementation dependent unless you use the SQL ORDER statement
- ResultSetMetaData meta = rs.getMetaData();
- int colmax = meta.getColumnCount();
- int i;
- Object o = null;
- // the result set is a cursor into the data. You can only
- // point to one row at a time
- // assume we are pointing to BEFORE the first row
- // rs.next() points to next row and returns true
- // or false if there is no next row, which breaks the loop
- for (; rs.next(); ) {
- for (i = 0; i < colmax; ++i) {
- o = rs.getObject(i + 1); // Is SQL the first column is indexed
- // with 1 not 0
- System.out.print(o.toString() + " ");
- }
- System.out.println(" ");
- }
- } //void dump( ResultSet rs )
- public static void main(String[] args) {
- Testdb db = null;
- try {
- db = new Testdb("db_file");
- } catch (Exception ex1) {
- ex1.printStackTrace(); // could not start db
- return; // bye bye
- }
- try {
- //make an empty table
- //
- // by declaring the id column IDENTITY, the db will automatically
- // generate unique values for new rows- useful for row keys
- db.update(
- "CREATE TABLE sample_table ( id INTEGER IDENTITY, str_col VARCHAR(256), num_col INTEGER)");
- } catch (SQLException ex2) {
- //ignore
- //ex2.printStackTrace(); // second time we run program
- // should throw execption since table
- // already there
- //
- // this will have no effect on the db
- }
- try {
- // add some rows - will create duplicates if run more then once
- // the id column is automatically generated
- db.update(
- "INSERT INTO sample_table(str_col,num_col) VALUES('Ford', 100)");
- db.update(
- "INSERT INTO sample_table(str_col,num_col) VALUES('Toyota', 200)");
- db.update(
- "INSERT INTO sample_table(str_col,num_col) VALUES('Honda', 300)");
- db.update(
- "INSERT INTO sample_table(str_col,num_col) VALUES('GM', 400)");
- // do a query
- db.query("SELECT * FROM sample_table WHERE num_col < 250");
- // at end of program
- db.shutdown();
- } catch (SQLException ex3) {
- ex3.printStackTrace();
- }
- } // main()
- } // class Testdb
发表评论
-
优化数据库前,可以问自己的10个问题
2009-12-25 13:17 971在 优化你的数据库时,你可能没有用到这些细节的优点。以 ... -
Sequoia(基于JDBC的数据库集群中间件)用户手册
2008-12-30 08:54 3469http://haha8.runsky.com/forum/s ... -
优秀的开源MySql开发/管理软件集合
2008-12-01 12:32 2123MySql是目前应用最广泛 ... -
MySQL和Postgres的比较
2008-08-27 12:10 1823我使用哪个数据库:Post ... -
Navicat 管理mysql不错
2007-11-14 08:58 1684Navicat 管理mysql不错 javaeye上附 ... -
Derby入门
2007-09-21 22:01 1290http://www.blogjava.net/mrzha ... -
Hsqldb初学
2007-09-15 01:22 4253java 代码 用了一下Hsqldb,感觉很精 ... -
org_myoodb_tools_classes 类图
2007-09-03 10:09 1102... -
myoodb_exception类图
2007-09-03 10:08 1195... -
面向对象的DBMS
2007-08-31 14:06 27931.数据库技术的发展 从60年代至今的30年中,信 ... -
org_myoodb_base相关类图
2007-08-29 17:06 1091... -
myoodb -objects类图
2007-08-29 10:29 1179动物的图 -
myoodb_extensions
2007-08-27 18:04 1154collectable 集合 Collectable ... -
myoodb例子的功能简单介绍
2007-08-24 16:45 1928# MyOODB - all database ... -
myoodb快速指南(翻译)
2007-08-21 13:48 2804myoodb快速指南 myoodb是一个面向对象的数据库,他 ...
相关推荐
hsqldb jdbc driver适合于hsqldb
**JDBC-HSQLDB简介** JDBC(Java Database Connectivity)是Java编程语言中用来规范客户端程序如何访问数据库的应用程序接口,提供了诸如查询和更新数据库中数据的方法。HSQLDB(HyperSQL Database)则是一个轻量级...
在本篇文章中,我们将深入探讨如何使用HSQLDB,并通过`HSQLDB_Client`类启动数据库,以及如何使用JDBC进行数据操作。 首先,HSQLDB的便捷之处在于其内置的服务器模式,允许开发者在应用程序中直接启用数据库服务。...
Class.forName("org.hsqldb.jdbc.JDBCDriver"); Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:test", "SA", ""); ``` 这里的`org.hsqldb.jdbc.JDBCDriver`是HSQLDB的JDBC驱动类,`jdbc:hsqldb:...
通过JDBC,我们可以使用`jdbc:hsqldb:hsql://localhost:9002/test`连接到服务器。 - **In-Process (Standalone)模式**:在这种模式下,数据库与应用程序在同一进程中运行,访问速度最快。但是,它仅限于当前进程,...
主要的类包括`org.hsqldb.Server`(服务器进程)、`org.hsqldb.jdbc.JDBCConnection`(JDBC连接)以及`org.hsqldb.Statement`(SQL语句执行)等。 ### 工具集成 HSQLDB常被用作开发和测试环境中的数据库,因为它...
使用JDBC(Java Database Connectivity)可以连接到HSQLDB。以下是一个简单的示例: ```java Class.forName("org.hsqldb.jdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://...
标题中的“HSQL JDBC操作”指的是使用Java的JDBC(Java Database Connectivity)接口与HSQLDB(HyperSQL数据库)进行交互。HSQLDB是一个轻量级、开源的关系型数据库管理系统,广泛用于测试和开发环境中,因为它启动...
1. **加载JDBC驱动**:在Java程序中,我们需要通过`Class.forName()`方法加载HSQldb的JDBC驱动。 2. **建立连接**:使用`DriverManager.getConnection()`方法,指定数据库URL,通常以`jdbc:hsqldb:`开头,可以是内存...
try (JDBCConnection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/mydb", "sa", "")) { // 执行SQL操作... } catch (SQLException e) { e.printStackTrace(); } } } ``` 三、HSQDDL的...
在使用HSQldb-2.2.8时,开发者通常会通过下载解压后的文件,找到对应的JDBC驱动(通常为`hsqldb.jar`),将其添加到项目的类路径中,然后通过JDBC API连接到数据库。HSQldb的配置文件(如`hsqldb.properties`)可以...
<property name="hibernate.connection.driver_class">org.hsqldb.jdbc.JDBCDriver <property name="hibernate.connection.url">jdbc:hsqldb:mem:testdb <property name="hibernate.connection.username">sa ...
1. **连接数据库**: 使用JDBC驱动程序连接到HSQLDB服务器。例如: ```java Class.forName("org.hsqldb.jdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/mydb", "sa...
1. JDBC驱动:HSQldb可能需要其他数据库系统的JDBC驱动,以便进行数据迁移、备份或同步。例如,如果你需要将HSQldb的数据导入导出到MySQL或Oracle,那么对应的JDBC驱动是必不可少的。 2. 兼容库:有时,为了兼容...
2. **连接数据库**:使用JDBC驱动进行连接,如`jdbc:hsqldb:hsql://localhost/test`,其中`test`是数据库名。 3. **创建表**:通过SQL语句`CREATE TABLE`定义表结构,如`CREATE TABLE Users (id INT PRIMARY KEY, ...
7. **网络协议支持**:通过JDBC(Java Database Connectivity)接口与应用程序交互,并支持TCP/IP网络通信,允许远程连接。 **HSQldb与JDK版本匹配的重要性:** 不同版本的HSQldb与特定的JDK版本匹配,是因为编译时...
HSQldb自带了`DatabaseManagerSwing`和`DatabaseManager`两个数据库管理工具,它们通过JDBC连接到HSQldb,方便进行数据库管理和查询操作。 **数据库关闭** 在任何模式下,可以使用SQL语句`SHUTDOWN`或`SHUTDOWN ...
- **数据库引擎**:介绍HSQLDB中可用的不同表类型(如临时表、持久化表)、约束和索引机制、SQL支持情况及JDBC接口的使用。 #### 四、SQL问题详解 - **对SQL标准的支持**:HSQLDB遵循并扩展了SQL-92标准,支持大...