ch5_jdbc_triggers

ch5_jdbc_triggers - Chapter 5: Advanced SQL Chapter Chapter...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 5: Advanced SQL Chapter 5: Advanced SQL
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
©Silberschatz, Korth and Sudarshan 5.2 Database System Concepts - 6 th Edition Chapter 5: Advanced SQL Chapter 5: Advanced SQL Accessing SQL From a Programming Language Dynamic SQL JDBC and ODBC Embedded SQL SQL Data Types and Schemas [skipping] Functions and Procedural Constructs [mostly skipping] Triggers Recursive Queries [skipping] Advanced Aggregation Features [skipping] OLAP [skipping]
Background image of page 2
©Silberschatz, Korth and Sudarshan 5.3 Database System Concepts - 6 th Edition JDBC and ODBC JDBC and ODBC API (application-program interface) for a program to interact with a database server Application makes calls to Connect with the database server Send SQL commands to the database server Fetch tuples of result one-by-one into program variables ODBC (Open Database Connectivity) works with C, C++, C#, and Visual Basic Other API’s such as ADO.NET sit on top of ODBC JDBC (Java Database Connectivity) works with Java
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
©Silberschatz, Korth and Sudarshan 5.4 Database System Concepts - 6 th Edition JDBC JDBC JDBC is a Java API for communicating with database systems supporting SQL. JDBC supports a variety of features for querying and updating data, and for retrieving query results. JDBC also supports metadata retrieval, such as querying about relations present in the database and the names and types of relation attributes. Model for communicating with the database: Open a connection Create a “statement” object Execute queries using the Statement object to send queries and fetch results Exception mechanism to handle errors
Background image of page 4
©Silberschatz, Korth and Sudarshan 5.5 Database System Concepts - 6 th Edition JDBC Code JDBC Code public static void JDBCexample(String dbid, String userid, String passwd) { try { Class.forName ("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection( "jdbc:oracle:thin: @ db.yale.edu:2000:univdb", userid, passwd); Statement stmt = conn.createStatement(); … Do Actual Work …. stmt.close(); conn.close(); } catch (SQLException sqle) { System.out.println("SQLException : " + sqle); } }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
©Silberschatz, Korth and Sudarshan 5.6 Database System Concepts - 6 th Edition JDBC Code (Cont.) JDBC Code (Cont.) Update to database try { stmt.executeUpdate( "insert into instructor values(’77987’, ’Kim’, ’Physics’, 98000)"); } catch (SQLException sqle) { System.out.println("Could not insert tuple. " + sqle); } Execute query and fetch and print results ResultSet rset = stmt.executeQuery( "select dept_name, avg (salary) from instructor group by dept_name"); while (rset.next()) { System.out.println(rset.getString("dept_name") + " " + rset.getFloat(2)); }
Background image of page 6
©Silberschatz, Korth and Sudarshan 5.7 Database System Concepts - 6 th Edition JDBC Code Details JDBC Code Details Getting result fields: rs.getString(“dept_name”) and rs.getString(1) equivalent if
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/10/2011 for the course CS 308 taught by Professor Frankl during the Spring '11 term at NYU Poly.

Page1 / 35

ch5_jdbc_triggers - Chapter 5: Advanced SQL Chapter Chapter...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online