Java Reference
In-Depth Information
3. Creating a Table
Example
create table Accounts(acctNum int
primary key
, surname
varchar(15), fi rstNames varchar(25), balance real);
[Note the setting of the primary key!]
4. Inserting Rows
Example
insert into Accounts values(123456, 'Black', 'James
Michael', 123.45);
5. Selecting, Updating and Deleting Rows
Examples
select * from Accounts;
update Accounts set balance=999.99 where acctNum=123456;
delete from Accounts where acctNum = 234567;
6. Disconnecting and Reconnecting
disconnect;
connect 'jdbc:derby:<DbPath&Name>';
Note that
relative addressing
may be used.
7. Quitting
exit;
8. Using Scripts
Unless dealing with only one or two SQL statements, one should always use ij
scripts. First place all of the required SQL statements into a text fi le with an
appropriate name (e.g.,
AccountsScript.sql
). This fi le may then be run in any one
of the following three ways…
( i )
Use the ij command, supplying the input fi le as a command line argument.
Example
java org.apache.derby.tools.ij AccountsScript.sql
(ii)
Redirect standard input [see Sect.
4.3
]
to come from the script fi le.
Example
java org.apache.derby.tools.ij < AccountsScript.sql
(iii)
From the ij prompt, use the
run
command.
Example
run 'AccountsScript.sql';
Search WWH ::
Custom Search