Presentation is loading. Please wait.

Presentation is loading. Please wait.

DataBases and SQL INFSY 547 Spring 2007. Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:

Similar presentations


Presentation on theme: "DataBases and SQL INFSY 547 Spring 2007. Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:"— Presentation transcript:

1 DataBases and SQL INFSY 547 Spring 2007

2 Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19: Review Form ideas, Team Meetings and presentation guidelines April 26: Project Due Date Develop presentations May 3: Final Presentation and Party

3 Structured Query Language (SQL)  Used widely to interact with a variety of relational data bases  Oracle database management system

4 Relational Databases Relational databases stores data in tables Rows : represents a record Columns : represents individual fields of data Primary key: a column or group of columns in a table with a unique value Select stmts: specify which data to look at in a table Queries: define what will be selected from a table or group of tables

5 Sample Relational Data Base StudentTable studentId*studentFirstNamestudentLastName GradeTable studentcoursegrade  One:Many  * indicates primary key  minimally one table

6 Relational Databases –Foreign key:a column that is a primary key in another table –Referential Integrity: every foreign key must appear as another table’s primary key SELECT title, editionNumber, copyright FROM Titles WHERE copyright > 2000; sql statement

7 Creating a Database with SQL in Oracle Click on SQLPlus Note: 1) first time password is userid and new one will be required. 2) if already on the system, password is as before

8 Now You are Ready to Enter Commands from the Command Line!

9 Creating a Database with SQL in Oracle Create a table (create one of your choice) CREATE TABLE EmployeeTable ( emp_id char (5), emp-lName char (20), emp_fName char (15), emp_dept char (5), PRIMARY KEY (emp_id));

10 Relational Databases Other SQL Statements: INSERT INTO EmployeeTable (empId, fName, lName, dept) VALUES ( ‘101,‘Sue’, ‘Smith’,’MRKT’); UPDATE EmployeeTable SET lName = ‘Jones’ WHERE lName = ‘Smith’ and fName = ‘Sue’;

11 Other SQL Statements: DELETE FROM EmployeeTable WHERE lastName = ‘Jones’ and firstName = ‘Sue’; List your table name(s): SELECT table_name from user_tables;

12 SQL Statements StatementPurpose SELECTSelects rows from a table INSERTInserts rows into a table DELETEDeletes rows from a table UPDATEUpdates rows in a table COMMITCommits a transaction ROLLBACKRolls back a transaction GRANTGrants security rights REVOKERevokes security rights

13 Work with your table!

14 Granting Privileges GRANT SELECT ON EMPLOYEE TO JTS1; GRANT UPDATE ON EMPLOYEE TO JTS1; GRANT DELETE ON EMPLOYEE TO JTS1; GRANT ALTER ON EMPLOYEE TO JTS1;

15 Java Application JDBC Driver Manager JDBC-ODBC Bridge Vendor JDBC Driver Vendor OBDC Driver DataBASE Servlets and Java Server Pages, M. Hall and L. Brown, Sun Vendor Drivers result in best performance

16 For vendor JDBC Must be compiled with a special library file –classes12.jar (comes with Oracle products or download from my personal site) –Place in the common/lib in the TomCat directory http://www.personal.psu.edu/gjy1/infsy547/classes.jar

17 Java DataBase Connectivity (JDBC)  Connect to Oracle  Build queries in servlets  Display database information

18 Database Server Interpret SQL statements Optimize queries Prevent errors connected to concurrent user access Detect and act upon deadlock Administer security Administer backup and recovery

19 Relational Middleware SQL API (Application Programming Interface) –Facility to embed SQL code within procedural languages Database Driver –Software which format SQL statements and send them to the server Protocol Stack –Used for communicating between client and server

20 Relational Middleware

21 JDBC Steps to be programmed to access a relational database using Java 1.Load a driver compatible with the database being used. 2.Establish a connection to the database 3.Associate an SQL statement with this connection 4.Execute the SQL statement 5.SQL statement will produce a table stored in a ResultSet object.

22 JDBC 6.When processing is complete, database is closed 7.Connection to the database is closed; be sure to do so in the program

23 JDBC The JBDC API is contained in the java.sql package which contains: –Eight interfaces –Six classes –Three exceptions

24 JDBC DriverManager Class –Class manages JDBC drivers and provides uniform interface for establishing connections to databases

25 JDBC  Load the driver by calling : Class.forName(driverClassName); Class.forName( "oracle.jdbc.driver.OracleDriver" ); If the driver can’t be loaded, a ClassNotFoundException is thrown.

26 JDBC If the connection can’t be made, an SQLException is thrown.

27 JDBC A Connection (or session) interface must be implemented DriverManager.getConnection(String name, String user, String password); = DriverManager.getConnection("jdbc:oracle:thin:@146.186.8 4.66:1521:CLDB",“ ",”<password");


Download ppt "DataBases and SQL INFSY 547 Spring 2007. Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:"

Similar presentations


Ads by Google