Kira-2006
-仅仅是一阵风也罢了,偏偏是这样永恒, 仅仅是一场梦也罢了,偏偏是如此的真实,
posts - 4,comments - 7,trackbacks - 0

使用Ant操作hsql数据库的例子:

<?xml version="1.0"?>

<project name="timexdb">
 <property name="hjar" value="WebRoot/WEB-INF/lib/hsqldb.jar" />
 <property name="hclass" value="org.hsqldb.Server" />
 <property name="hfile" value="-database.0 data/gogoudb" />
 <property name="halias" value="gogou" />
 <property name="hport" value="9005" />

 <target name="starthsql">
  <java fork="true"
   classname="${hclass}"
   classpath="${hjar}"
   args="${hfile} -dbname.0 ${halias} -port ${hport}" />
 </target>

 <target name="execddl">
  <sql classpath="${hjar}"
   driver="org.hsqldb.jdbcDriver"
   url="jdbc:hsqldb:hsql://localhost:${hport}/${halias}"
   userid="sa"
   password=""
   print="yes">

-- SQL script for TimeX
-- Step 1: Drop objects if they exist
DROP TABLE Department IF EXISTS;
DROP TABLE Employee IF EXISTS;
DROP TABLE Timesheet IF EXISTS;
DROP INDEX TimesheetIndex IF EXISTS;
DROP INDEX DepartmentCodeIndex IF EXISTS;
DROP INDEX EmployeeIdIndex IF EXISTS;
DROP TABLE customer IF EXISTS;
DROP TABLE Item IF EXISTS;
DROP TABLE Item_subType IF EXISTS;
DROP TABLE Item_superType IF EXISTS;
DROP TABLE orders IF EXISTS;
   
-- Step 2: Create tables
CREATE TABLE Item_superType
(
   superID BIGINT primary key,
   superTypeName VARCHAR(20) NOT NULL
);

CREATE TABLE Item_subType
(
   subID BIGINT primary key,
   superID BIGINT,
   subTypeName VARCHAR(20) NOT NULL,
   FOREIGN KEY(superID) REFERENCES Item_superType(superID)
);

CREATE TABLE Item
(
   itemID BIGINT primary key,
   subID BIGINT,
   itemName VARCHAR(20) NOT NULL,
   Introduce VARCHAR(50) ,
   Price VARCHAR(6) NOT NULL,
   nowPrice VARCHAR(6) NOT NULL,
   smallPicture VARCHAR(10) NOT NULL,
   bigPicture VARCHAR(10) NOT NULL,
   inTime datetime ,
   newItem INT ,
   Rebate INT ,
   Hit INT ,
   FOREIGN KEY(subID) REFERENCES Item_subType(subID)
);

CREATE TABLE customer
(
    userID BIGINT IDENTITY,
    username VARCHAR(20) NOT NULL,
    Password  VARCHAR(20) NOT NULL,
    userCity  VARCHAR(20) ,
    userEmail  VARCHAR(20) NOT NULL,
    userAge  INT ,
    userSex  INT
 );
     
CREATE TABLE orders
(
 orderID BIGINT IDENTITY,
    consigneeName VARCHAR(20) NOT NULL,
    consigneeAddress VARCHAR(20) NOT NULL,
    Postalcode VARCHAR(6) NOT NULL,
    Telephone VARCHAR(20) NOT NULL,
    carryMethod VARCHAR(10) NOT NULL,
    Orderdate  datetime  
);
       
CREATE TABLE visualOrder
(
     id BIGINT  IDENTITY,
     itemID BIGINT,
     userID BIGINT,
     orderID BIGINT,
     itemNumber BIGINT NOT NULL,
     FOREIGN KEY(itemID) REFERENCES Item(itemID),
     FOREIGN KEY(userID) REFERENCES customer(userID),
     FOREIGN KEY(orderID) REFERENCES orders(orderID)
);

-- Step 3: Create indexes
CREATE UNIQUE INDEX visualOrderIndex ON visualOrder (userID);
CREATE UNIQUE INDEX ItemIndex ON Item (itemID);
CREATE UNIQUE INDEX userIdIndex ON customer (userId);
   
create view newItem_statistic as  select * from item where item.newItem = 1;
create view saleItem_statistic as  select * from item where item.Rebate = 1;

-- Step 4: Insert some reference and test data
INSERT INTO customer (userName, Password,userEmail)
        VALUES ('kira', 'kira','xuguoliang@sina.com');


-- Step 5: Verify tables and test data look ok
SELECT * FROM customer;

      </sql>
 </target>
 <target name="hsqldm">
  <java fork="true" classpath="${hjar}" classname="org.hsqldb.util.DatabaseManagerSwing" />
 </target>
 <target name="sqltool">
  <java fork="true" classpath="${hjar}" classname="org.hsqldb.util.SqlTool" args="localhost-sa" />
 </target>
</project>

posted on 2008-04-26 18:25 Kira-2006 阅读(281) 评论(0)  编辑  收藏 所属分类: hsql

只有注册用户登录后才能发表评论。


网站导航: