Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Database Connectivity By: Abe Marji CS616. Agenda 1.Quick Review of Databases 2.What is SQL? 3.What is JDBC? 4.Advanced Functions of JDBC 5.Summary.

Similar presentations


Presentation on theme: "Java Database Connectivity By: Abe Marji CS616. Agenda 1.Quick Review of Databases 2.What is SQL? 3.What is JDBC? 4.Advanced Functions of JDBC 5.Summary."— Presentation transcript:

1 Java Database Connectivity By: Abe Marji CS616

2 Agenda 1.Quick Review of Databases 2.What is SQL? 3.What is JDBC? 4.Advanced Functions of JDBC 5.Summary

3 What are Databases? A database is a collection of tables, which organizes and stores information The columns each contain a category of information. A table consists of rows (records) of columns (fields) The rows contain the information for each of the categories related to an individual event

4 Database Samples COL1COL2COL3COL4COL5COL6 ROW1 ROW2 ROW3 ROW4 ROW5 ROW6 ROW7 Columns (Attributes) Rows (Data) DATA Table 1 Table 2 Relationship

5 What is SQL? SQL is “Structure Query Language” It is considered to be the standard for database handling. SQL provides functions to View, Update, Delete, and Add data to a database. SQL also handles the database structure such as changing the properties of its tables or adding or delete new Tables

6 Types of SQL Calls SELECT – Queries existing Data UPDATE – Updates existing data INSERT – Adds new data in a table DELETE – Deletes data or tables CREATE – Creates new tables

7 Samples of SQL Queries A simple example of an SQL statement is Standard SQL Statement: Format: “Function Col from condition” “SELECT * FROM Animal“ Not Case Sensitive: “Select NaMe from ANIMAL“ Data is Case Sensitive: “SELECT * from CUSTOMERS where NAME =‘JOE’” Is different from “SELECT * from CUSTOMERS where NAME =‘Joe’”

8 SQL Standard Data Types Java typeSQL Type Values CharChar or CharacterString IntInteger32 Bit ShortSmall Integer16 Bit LongBig Integer64 Bit DoubleDouble15 Digits DoubleFloat15 Digits FloatReal7 Digits ByteTiny Integer8 Bits Java.math.BigDecimalNumericFixed Point with Java.math.BigDecimalDecimaldecimal Digits

9 SQL Data Types – Other Java typeSQL Type Values BooleanBitTrue/False Java.sql.DateDateMonth/Day/Year Java.sql.timeTimeHour / Min / Sec Java.sql.datestampdatestampDate and Time

10 What is JDBC? JDBC is JAVA Database Connectivity. JAVA Applications uses JDBC to connect to a Database. JDBC API are available from Sun Systems. Different Database Vendors make their own JDBC Drivers.

11 JDBC Driver Layer Model

12 Querying through Drivers

13 Sun’s JDBC/ODBC Bridge

14 Vendor Specific JDBC Drivers

15 Creating an ODBC Connection

16 Typical JDBC Code import java.sql.*; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); a_connection = DriverManager.getConnection ("jdbc:odbc:CS616DB",“admin",“password"); a_statement = a_connection.createStatement(); ResultSet rs = a_statement.executeQuery("SQL Query”);

17 Sample JDBC Code Static Connection DriverManager.getConnection (String datasource, String userid, String password) Connection a_conn = DriverManager.getConnection(“jdbc:odbc: CS616DB”, “Admin”, “password”);

18 JDBC Exceptions Exceptions occur in Java when errors occur in SQL code. Catching exceptions means dealing with those errors. You can use several methods to get further information on an SQLException: getSQLState() getErrorCode() getNext Exception() getWarnings()

19 Flow for JDBC Exceptions

20 Advanced Functions JDBC has the ability to support Prepared Statements and CALL statements Prepared Statements lets you use one sql statement to run different queries by passing it different parameters. CALL statements allows the developer to use database queries that are created by the Database Admin.

21 Summary JDBC is used in applications that require database connectivity Different Vendors support various types of JDBC Drivers. JDBC can take advantage of advanced SQL functions/queries using the CALL and Execute procedures()


Download ppt "Java Database Connectivity By: Abe Marji CS616. Agenda 1.Quick Review of Databases 2.What is SQL? 3.What is JDBC? 4.Advanced Functions of JDBC 5.Summary."

Similar presentations


Ads by Google