Java Reference
In-Depth Information
version: 10.8.1.2 - (1095077)
Found support for locale: [zh_TW]
version: 10.8.1.2 - (1095077)
------------------------------------------------------
The
ij
script is useful for creating a database and initializing a user's
schema
(a
namespace that logically organizes tables and other database objects) by running a
script file that specifies appropriate DDL statements. For example, you've created an
EMPLOYEES
table with its
NAME
and
PHOTO
columns, and have created a
cre-
ate_emp_schema.sql
scriptfileinthecurrentdirectorythatcontainsthefollowing
line:
CREATE TABLE EMPLOYEES(NAME VARCHAR(30), PHOTO BLOB);
The following embedded
ij
script session creates the
employees
database and
EMPLOYEES
table:
C:\db>ij
ij version 10.8
ij> connect 'jdbc:derby:employees;create=true';
ij> run 'create_emp_schema.sql';
ij> CREATE TABLE EMPLOYEES(NAME VARCHAR(30), PHOTO BLOB);
0 rows inserted/updated/deleted
ij> disconnect;
ij> exit;
C:>\db>
The
connect
command causes the
employees
database to be created—I'll have
more tosayabout this command's syntax whenIintroduce JDBC later inthis chapter.
The
run
command causes
create_emp_schema.sql
to execute, and the subse-
quent pair of lines is generated as a result.
The
CREATE TABLE EMPLOYEES(NAME VARCHAR(30), PHOTO BLOB);
line is an SQL statement for creating a table named
EMPLOYEES
with
NAME
and
PHOTO
columns.Dataitemsenteredintothe
NAME
columnareofSQLtype
VARCHAR
(avaryingnumberofcharacters—astring)withamaximumof
30
characters,anddata
itemsenteredintothe
PHOTO
columnareofSQLtype
BLOB
(abinarylargeobject,such
as an image).
Note
IspecifySQLstatementsinuppercase,butyoucanalsospecifytheminlower-
case or mixed case.