Java DB Command-Line Tools

Một phần của tài liệu Beginning Java SE 6 Platform From Novice to Professional phần 5 pptx (Trang 30 - 34)

The binsubdirectories of the embeddedand NetworkServerdirectories contain three Windows and Unix script files for launching command-line tools:

• Run sysinfoto view the Java environment/Java DB configuration.

• Run ijto run scripts that execute ad hoc SQL commands and perform repetitive tasks.

• Run dblookto view all or part of a database’s Data Definition Language (DDL).

If you experience trouble with Java DB (such as not being able to connect to a data- base), you can run sysinfoto see if the problem is configuration related. The embedded version of this tool reports various settings under the Java Information, Derby Informa- tion, and Locale Information headings. It outputs the following information on my platform:

--- Java Information --- Java Version: 1.6.0

Java Vendor: Sun Microsystems Inc.

Java home: c:\progra~1\java\jdk1.6.0\jre

Java classpath: c:\PROGRA~1\Java\JDK16~1.0\db\lib\derby.jar;

c:\PROGRA~1\Java\JDK16~1.0\db\lib\derbytools.jar;

OS name: Windows XP OS architecture: x86 OS version: 5.1

Java user name: Jeff Friesen

Java user home: C:\Documents and Settings\Jeff Friesen

Java user dir: C:\PROGRA~1\Java\JDK16~1.0\db\FRAMEW~1\NETWOR~1\bin java.specification.name: Java Platform API Specification

java.specification.version: 1.6 --- Derby Information --- JRE - JDBC: Java SE 6 - JDBC 4.0

[C:\Program Files\Java\jdk1.6.0\db\lib\derby.jar] 10.2.1.7 - (453926) [C:\Program Files\Java\jdk1.6.0\db\lib\derbytools.jar] 10.2.1.7 - (453926) ---

--- Locale Information --- Current Locale : [English/United States [en_US]]

Found support for locale: [de_DE]

version: 10.2.1.7 - (453926) Found support for locale: [es]

version: 10.2.1.7 - (453926) Found support for locale: [fr]

version: 10.2.1.7 - (453926) Found support for locale: [it]

version: 10.2.1.7 - (453926) Found support for locale: [ja_JP]

version: 10.2.1.7 - (453926) Found support for locale: [ko_KR]

version: 10.2.1.7 - (453926) Found support for locale: [pt_BR]

version: 10.2.1.7 - (453926) Found support for locale: [zh_CN]

version: 10.2.1.7 - (453926) Found support for locale: [zh_TW]

version: 10.2.1.7 - (453926)

The client/server version of sysinfohas more information to report. Because the network server uses the Distributed Relational Database Architecture (DRDA) protocol to receive and reply to client queries, the output begins with a Derby Network Server Information section that lists the values of various DRDA properties:

--- Derby Network Server Information ---

Version: CSS10020/10.2.1.7 - (453926) Build: 453926 DRDA Product Id: CSS10020 -- listing properties --

derby.drda.maxThreads=0 derby.drda.keepAlive=true derby.drda.minThreads=0

derby.drda.portNumber=1527 derby.drda.logConnections=false derby.drda.timeSlice=0

derby.drda.startNetworkServer=false derby.drda.host=localhost

derby.drda.traceAll=false

--- Java Information --- Java Version: 1.6.0

Java Vendor: Sun Microsystems Inc.

Java home: c:\progra~1\java\jdk1.6.0\jre

Java classpath: c:\progra~1\java\jdk1.6.0\db\lib\derby.jar;

c:\progra~1\java\jdk1.6.0\db\lib\derbytools.jar;

c:\progra~1\java\jdk1.6.0\db\lib\derbynet.jar;

c:\progra~1\java\jdk1.6.0\db\lib\derby.jar;

c:\progra~1\java\jdk1.6.0\db\lib\derbytools.jar;

c:\progra~1\java\jdk1.6.0\db\lib\derbynet.jar;

OS name: Windows XP OS architecture: x86 OS version: 5.1

Java user name: Jeff Friesen

Java user home: C:\Documents and Settings\Jeff Friesen

Java user dir: C:\PROGRA~1\Java\jdk1.6.0\db\frameworks\NetworkServer\bin java.specification.name: Java Platform API Specification

java.specification.version: 1.6 --- Derby Information --- JRE - JDBC: Java SE 6 - JDBC 4.0

[C:\Program Files\Java\jdk1.6.0\db\lib\derby.jar] 10.2.1.7 - (453926) [C:\Program Files\Java\jdk1.6.0\db\lib\derbytools.jar] 10.2.1.7 - (453926) [C:\Program Files\Java\jdk1.6.0\db\lib\derbynet.jar] 10.2.1.7 - (453926) ---

--- Locale Information --- Current Locale : [English/United States [en_US]]

Found support for locale: [de_DE]

version: 10.2.1.7 - (453926) Found support for locale: [es]

version: 10.2.1.7 - (453926) Found support for locale: [fr]

version: 10.2.1.7 - (453926) Found support for locale: [it]

version: 10.2.1.7 - (453926) Found support for locale: [ja_JP]

version: 10.2.1.7 - (453926)

Found support for locale: [ko_KR]

version: 10.2.1.7 - (453926) Found support for locale: [pt_BR]

version: 10.2.1.7 - (453926) Found support for locale: [zh_CN]

version: 10.2.1.7 - (453926) Found support for locale: [zh_TW]

version: 10.2.1.7 - (453926)

Note The client/server version of sysinfoduplicates the classpath entry, which is most likely due to this version invoking org.apache.derby.drda.NetworkServerControl sysinfoinstead of org.

apache.derby.tools.sysinfo(which is invoked by the embedded version).

The ijscript is useful for creating a database and initializing a user’s schema (a namespace that logically organizes database objects) by running a script file that specifies appropriate DDL statements. For example, suppose that you want to create the EMPLOYEE table described earlier, with its NAME and PHOTO columns. The following embedded ijscript session accomplishes this task:

C:\db>ij ij version 10.2

ij> connect 'jdbc:derby:employee;create=true';

ij> run 'create_emp_schema.sql';

ij> CREATE TABLE EMPLOYEE(NAME VARCHAR(30), PHOTO BLOB);

0 rows inserted/updated/deleted ij> disconnect;

ij> exit;

C:>\db>

As indicated in the script session, the contents of create_emp_schema.sqlare CREATE TABLE EMPLOYEE(NAME VARCHAR(30), PHOTO BLOB);. After run 'create_emp_schema.sql'fin- ishes, the specified EMPLOYEE table is added to the newly created EMPLOYEE database.

To verify the table’s existence, run dblookagainst the employeedirectory, as the following session demonstrates:

C:\db>dblook -d jdbc:derby:employee -- Timestamp: 2007-05-31 19:08:20.375 -- Source database is: employee

-- Connection URL is: jdbc:derby:employee

-- appendLogs: false

-- --- -- DDL Statements for tables

-- ---

CREATE TABLE "APP"."EMPLOYEE" ("NAME" VARCHAR(30), "PHOTO" BLOB(2147483647));

C:\db>

All database objects (such as tables and indexes) are assigned to user and system schemas, which logically organize these objects in the same way that packages logically organize classes. When a user creates or accesses a database, Java DB uses the specified username as the namespace name for newly added database objects. In the absence of a username, Java DB chooses APP, as shown in the preceding example.

Một phần của tài liệu Beginning Java SE 6 Platform From Novice to Professional phần 5 pptx (Trang 30 - 34)

Tải bản đầy đủ (PDF)

(51 trang)