Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems.

Slides:



Advertisements
Similar presentations
Owners Roles DB Objects Grant Revoke Grant Revoke Grant Revoke (*) with admin option Il ruolo …. È un set di system & object privileges Non appartiene.
Advertisements

Objective: To access a database from an application program (as opposed to interactive interfaces) Why? An interactive interface is convenient but not.
Embedded SQL John Ortiz. Lecture 15Embedded SQL2 Why Isn’t Interactive SQL Enough?  How to do this using interactive SQL?  Print a well-formatted transcript.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Distributed Application Development B. Ramamurthy.
M.P. Johnson, DBMS, Stern/NYU, Sp20041 C : Database Management Systems Lecture #18 Matthew P. Johnson Stern School of Business, NYU Spring, 2004.
1 JDBC Java Database Connectivity. 2 c.pdf
SPRING 2004CENG 3521 SQL: Constraints, Triggers, Embedded SQL Chapters: 5, 6.
1 C. Shahabi Application Programming for Relational Databases Cyrus Shahabi Computer Science Department University of Southern California
SQL/Server Stephen Cunningham Thema Davis. Problem Domain Designed for retrieval and management of data Defines the structures and operations of a data.
UFCE4Y UFCE4Y-20-3 Components and Services Julia Dawson.
DB2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/DB01/003 Version No:2.0a Session Plan SPUFI Hands On Introduction to Embedded SQL DCLGEN.
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
1 Section 6 Embedded SQL. 6-2 CA306 Embedded SQL Section Content 6.1Embedded SQL 6.2Java Database Connectivity 6.3Web Databases.
Getting connected.  Java application calls the JDBC library.  JDBC loads a driver which talks to the database.  We can change database engines without.
Accessing Databases with JDBC. Introduction to JDBC JDBC provides a standard library for accessing databases by using the JDBC API. JDBC standardizes.
Overview of JDBC and Pro*C 1 Overview of JDBC,Pro*C and Oracle connectivity on Omega CSE 5330 – Database Systems.
Database Management Systems 1 Oracle Programming.
JDBC. What is JDBC JDBC is an acronym for –Java Data Base Connectivity. It allows java/jsp program to connect to any database.
CSE470 Software Engineering Fall Database Access through Java.
Beginning Databases with JDBC Mike Bradley Adapted from and notes by Kevin Parker, Ph.D.
Database Application Development CS348 Introduction to Database Management Systems Fall CS348: Database applicaiton development.
Using Java with PSQL and Oracle Thanks to Drs. Raj and Liu for sharing some of these slides TRUDY: ALSO NEED SAMPLE PROGRAM.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 9- 1 DATADABASE PROGRAMMING 2Chapter 13 from our text.
1 No class Thurs. Oct. 2 E-day Exam 1 Thurs. Oct. 9 HW3 Oct. 2 to –Available Oct 2 only until 2 pm.
JDBC (Java Database Connectivity) SNU OOPSLA Lab. October 2005.
CS 405G: Introduction to Database Systems Database programming.
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
JDBC  The JDBC (Java Database Connectivity) API helps a Java program to access a database in a standard way  JDBC is a specification that tells the.
JDBC Enterprise Systems Programming. JDBC  Java Database Connectivity  Database Access Interface provides access to a relational database (by allowing.
Chapter 8 Databases.
Copyright  Oracle Corporation, All rights reserved. 6 Accessing a Database Using the JDBC API.
Copyright  Oracle Corporation, All rights reserved. 7 Accessing a Database Using SQLJ.
Programmatic SQL Shaista Khan CS 157B. Topic Embedded SQL statements in high-level programming languages.
Chapter 17 Accessing Databases with JDBC. JDBC JDBC provides a standard library for accessing relational databases. By using the JDBC API, you can access.
JDBC Database Programming in Java Prepared by., Mrs.S.Amudha AP/SWE.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
1 CS 430 Database Theory Winter 2005 Lecture 14: Additional SQL Topics.
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Java and Databases. JDBC Architecture Java Application JDBC API Data Base Drivers AccessSQL Server DB2InformixMySQLSybase.
COMP 321 Week 4. Overview Normalization Entity-Relationship Diagrams SQL JDBC/JDBC Drivers hsqldb Lab 4-1 Introduction.
DATABASE CONNECTIVITY TO MYSQL. Introduction =>A real life application needs to manipulate data stored in a Database. =>A database is a collection of.
Dr Gordon Russell, Napier University Unit Embedde SQL - V2.0 1 Embedded SQL Unit 5.1.
DataBases and SQL INFSY 547 Spring Course Wrap Up April 12: Complete Work on Servlets Review of Team Projects Close of Portfolio Work April 19:
JDBC CS 260 Database Systems. Overview  Introduction  JDBC driver types  Eclipse project setup  Programming with JDBC  Prepared statements  SQL.
Development Overview Pertemuan 11 Matakuliah: T0413 Tahun: 2009.
Access Databases from Java Programs via JDBC Tessema M. Mengistu Department of Computer Science Southern Illinois University Carbondale
Database Management Systems 1 Raghu Ramakrishnan Database Application Development Chpt 6 Xin Zhang.
Umair Javed©2005 Enterprise Application Development Java Database Connectivity (JDBC) JDBC1.
Introduction to JDBC Instructor: Mohamed Eltabakh 1.
Lu Wei1 Outline Introduction Basic SQL Setting Up and Using PostgreSQL Advanced SQL Embeded SQL.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Java Database Connectivity.
1 JDBC – Java Database Connectivity CS , Spring 2010.
Intro to JDBC Joseph Sant Applied Computing and Engineering Sciences Sheridan ITAL.
Chapter 7 Chapter 7 Java Database Connectivity using JSP 1 (IS 203) WebProgramming (IS 203) Web Programming.
CS422 Principles of Database Systems JDBC and Embedded SQL Chengyu Sun California State University, Los Angeles.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_Oracle10g_JDBC 1 Application Development (JDBC)
Java and database. 3 Relational Databases A relational Database consists of a set of simple rectangular tables or relations The column headings are.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Application Development Chapter 6.
Instructor: Jinze Liu Fall /8/2016Jinze University of Kentucky 2 Database Project Database Architecture Database programming.
Lec - 14.
Introduction to SQL Programming Techniques
JDBC – Java Database Connectivity
Web Technologies IT230 Dr Mohamed Habib.
HW#4 Making Simple BBS Using JDBC
Client Access, Queries, Stored Procedures, JDBC
Introduction to Server-Side Web Development using JSP and Databases
Interacting with Database
Presentation transcript:

Overview of JDBC and Pro*C 1 CSE 5330 – Database Systems

Overview of JDBC and Pro*C 2 Options for doing the project Windows application using Java – JDBC for database connectivity – Java AWT / Swing etc. for the GUI Menu driven program using Pro*C – If you know C, but not Java Web based application using CGI-Perl – Perl DBI module for database connectivity – CGI / HTML for the GUI Web based application using JSP, Java servlets, PHP etc. – Omega may not allow running some/all of these – Be prepared to demo on your own laptop etc.

Overview of JDBC and Pro*C 3 Java Database Connectivity (JDBC) JDBC provides a standardized library for accessing relational databases – Connecting to the database – Initiating queries – Creating stored (parameterized) queries – Data structure for the query result JDBC is not embedded SQL JDBC is located in java.sql package

Overview of JDBC and Pro*C 4 JDBC driver Java application JDBC driver manager JDBC API Oracle JDBC driver (classes12.zip) JDBC driver API Oracle database Client Server (omega)

Overview of JDBC and Pro*C 5 JDBC driver (continued) JDBC driver for Oracle needs to be on the client machine Available on omega at – /opt/oracle/product/ /jdbc/lib/classes12.zip The JDBC driver (classes12.zip) needs to be included in the runtime classpath

Overview of JDBC and Pro*C 6 Six steps in using JDBC 1.Load the driver 2.Establish a connection 3.Create a statement object 4.Execute a query 5.Process the results 6.Close the connection

Overview of JDBC and Pro*C 7 JDBC usage steps - details Step 1 : Load the driver try { Class.forName ("oracle.jdbc.driver.OracleDriver"); } catch(Exception e) { System.out.println("JDBC ORACLE driver failed to load"); }

Overview of JDBC and Pro*C 8 JDBC usage steps - details Step 2 : Establish a connection try { con = ta.edu:1521:CSE1"); } catch(Exception e) { System.out.println("Failed to connect to the database"); }

Overview of JDBC and Pro*C 9 JDBC usage steps - details Step 3 : Create a statement – Statement statement = con.createStatement(); Step 4 : Execute a query String query = “SELECT FNAME, SALARY FROM EMPLOYEE”; ResultSet rs = Statement.executeQuery(query); (For SELECT) String query = “UPDATE EMPLOYEE SET SALARY = WHERE FNAME = “John”; Statement.executeUpdate(query); (For UPDATE, INSERT, DELETE)

Overview of JDBC and Pro*C 10 JDBC usage steps - details Step 5 : Process the result While (rs.next()) { System.out.println(rs.getString(1) + “ “ + rs.getInt(2)); } First column has index 1, not 0 ResultSet provides various getXXX methods that take a column index, and return the data

Overview of JDBC and Pro*C 11 JDBC usage steps - details Step 6 : Close the connection – con.close(); As opening a connection is expensive, postpone this step if additional database operations are expected

Overview of JDBC and Pro*C 12 Online resources JDBC tutorial – JDBC API reference –

Overview of JDBC and Pro*C 13 Pro*C Embedded SQL – Allows you to embed SQL in C code Pro*C programC code Pre-compiler Executable C compiler Embedded SQL statementsSQL statements replaced By library calls SQLLIB Oracle runtime library

Overview of JDBC and Pro*C 14 Pro*C syntax SQL statements can be placed anywhere between a C block All SQL statements need to start with EXEC SQL and be terminated by a semicolon { int a; /*... */ EXEC SQL SELECT salary INTO :a FROM Employee WHERE SSN= ; /*... */ printf("The salary is %d\n", a); /*... */ } Be sure to include sqlca.h

Overview of JDBC and Pro*C 15 Connecting to the database Legal way char *username = "SCOTT"; char *password = "TIGER"; … EXEC SQL CONNECT :username IDENTIFIED BY :password; Illegal way – EXEC SQL CONNECT SCOTT IDENTIFIED BY TIGER; – EXEC SQL CONNECT 'SCOTT' IDENTIFIED BY 'TIGER';

Overview of JDBC and Pro*C 16 Dynamic sql Used to dynamically create entire SQL statements – char *s = "INSERT INTO emp VALUES(1234, 'jon', 3)"; – EXEC SQL PREPARE q FROM :s; – EXEC SQL EXECUTE q; Alternately, – char *s = "INSERT INTO emp VALUES(1234, 'jon', 3)"; – EXEC SQL EXECUTE IMMEDIATE :s;

Overview of JDBC and Pro*C 17 Host variables Key to the communication between the host program and the database They should be declared in a Declare section – EXEC SQL BEGIN DECLARE SECTION; – /* Declare all host variables inside this section: – */ char *uid = "scott/tiger"; –... – EXEC SQL END DECLARE SECTION;

Overview of JDBC and Pro*C 18 Transactions Sequence of SQL statements that are treated as a single unit of work Transaction ends when you issue – EXEC SQL COMMIT;

Overview of JDBC and Pro*C 19 Cursors Used for fetching multiple rows of data First, declare it. – EXEC SQL DECLARE emp_cursor CURSOR FOR – SELECT ename, empno, sal – FROM emp – WHERE deptno = :dept_number; Then, open it. – EXEC SQL OPEN emp_cursor; Fetch the records. – for (;;) – { – EXEC SQL FETCH emp_cursor INTO :emp_name1, :salary1; – }

Overview of JDBC and Pro*C 20 Cursors (continued) Finally, close it. – EXEC SQL CLOSE emp_cursor; Error handling – Every executable SQL statement returns a status code to the SQLCA variable sqlcode – A zero status code means that Oracle executed the statement without detecting an error or exception – A positive status code means that Oracle executed the statement but detected an exception – A negative status code means that Oracle did not execute the SQL statement because of an error.

Overview of JDBC and Pro*C 21 Pro*C set-up on omega All your Pro*C files should be named from lab1 to lab10 Use ‘make.proc labx’ to compile labx.pc This will precompile the.pc file to a C file, compile the C file and generate the executable for you Sample Pro*C program available. Run /home/a/ax/axs3919/lab2 /home/s/sh/sharmac/cse5330/spring2006/proC/lab2

Overview of JDBC and Pro*C 22 Online reference Pro*C/C++ Precompiler Programmer's Guide