Java Reference
In-Depth Information
Display 19.10
Relational Database Tables
Names
AUTHOR
AUTHOR_ID
URL
Adams, Douglas
1
http:// ...
Simmons, Dan
2
http:// ...
Stephenson, Neal
3
http:// ...
Titles
TITLE
ISBN
Snow Crash
0-553-38095-8
Endymion
0-553-57294-6
The Hitchhikers Guide to the Galaxy
0-671-46149-4
The Rise of Endymion
0-553-57298-9
BooksAuthors
ISBN
AUTHOR_ID
0-553-38095-8
3
0-553-57294-6
2
0-671-46149-4
1
0-553-57298-9
2
Display 19.11
Result of SQL Command in Text
Result
TITLE
ISBN
AUTHOR_ID
Snow Crash
0-553-38095-8
3
Endymion
0-553-57294-6
2
The Hitchhikers Guide to the Galaxy
0-671-46149-4
1
The Rise of Endymion
0-553-57298-9
2
This will produce the table shown in Display 19.11. That table contains all titles
with matching ISBN number and author ID. The ISBN number is the bridge that
connects the tables Titles and BooksAuthors .
As a more detailed example, let us connect to an embedded Derby database and
issue the SQL commands to create a new table, insert a new row (record) into the table,
select rows, and modify rows. Note that this is not a comprehensive list of commands
but rather a small subset of SQL.
First, our Java program must import the SQL libraries java.sql.Connection,
java.sql.DriverManager, java.sql.SQLException , and java.sql.Statement .
When processing results, we will also need to import java.sql.ResultSet . Next we
must load the database drivers:
String driver = "org.apache.derby.jdbc.EmbeddedDriver";
Class.forName(driver).newInstance( );
 
 
Search WWH ::




Custom Search