12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 1 ■ JAVA <strong>EE</strong> 6 AT A GLANCEij> create table customer (custId int primary key, firstname varchar(20),lastname varchar(20));This creates a customer table <strong>with</strong> a primary key column and two varchar(20) columns for the firstname and last name. You can display the description of the table by entering the following command:ij> describe customer;COLUMN_NAME |TYPE_NAME |DEC& |NUM& |COLUM& |COLUMN_DEF |CHAR_OCTE& |IS_NULL&-------------------------------------------------------------------------------------------------CUSTID |INTEGER |0 |10 |10 |NULL |NULL |NOFIRSTNAME |VARCHAR |NULL |NULL |20 |NULL |40 |YESLASTNAME |VARCHAR |NULL |NULL |20 |NULL |40 |YESNow that the table is created, you can add data using the insert SQL statement as follows:ij> insert into customer values (1, 'Fred', 'Chene');ij> insert into customer values (2, 'Sylvain', 'Verin');ij> insert into customer values (3, 'Robin', 'Riou');You can then use all the power of the SQL select statement to retrieve, order, or aggregate data.ij> select count(*) from customer;1-----------3ij> select * from customer where custid=3;CUSTID |FIRSTNAME |LASTNAME-----------------------------------------------------3 |Robin |Riouij> exit;To get the DDL of the created table, you can exit ij and run dblook against the Chapter01DBdatabase.C:\> dblook -d 'jdbc:derby://localhost:1527/Chapter01DB'-- Source database is: Chapter01DB-- Connection URL is: jdbc:derby://localhost:1527/Chapter01DB-- appendLogs: false-- ------------------------------------------------ DDL Statements for tables-- ----------------------------------------------CREATE TABLE "APP"."CUSTOMER" ("CUSTID" INTEGER NOT NULL, "FIRSTNAME" VARCHAR(20), "LASTNAME" VARCHAR(20));-- ------------------------------------------------ DDL Statements for keys-- ------------------------------------------------ primary/uniqueALTER TABLE "APP"."CUSTOMER" ADD CONSTRAINT "SQL0903154616250" PRIMARY KEY ("CUSTID");33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!