1 / 11

Impedance Mismatch Problem

Impedance Mismatch Problem. Problem : How to connect SQL statements with conventional programming languages. Different models of language SQL query returns relation (no pgmg-language access mechanisms) Data structures in pgmg languages (with access mechanisms)

dasha
Télécharger la présentation

Impedance Mismatch Problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Impedance Mismatch Problem • Problem: How to connect SQL statements with conventional • programming languages • Different models of language • SQL query returns relation (no pgmg-language access mechanisms) • Data structures in pgmg languages (with access mechanisms) • Passing data between these two models is not straightforward • Both languages have their strengths

  2. System Aspects of SQL • SQL statements are usually part of some larger piece of software Host language + Embedded SQL Preprocessor Host language + Function Calls Host-language Compiler Object-code program Changes SQL into something familiar to host language Embedded SQL approach Provided by DBMS vendor Call-level interface (CLI) approach SQL library

  3. SQL/Host Language Interface • Shared variables • Special Declare Section • Syntax • A variable with a colon prefix refers to data in the result of an SQL statement. • A variable with no colon prefix refers to data in as usual in a host language • EXEC SQL • Tells preprocessor that SQL code is coming • Followed by other SQL statements

  4. Example

  5. JDBC • Java Database Connectivity • Call-Level-Interface (CLI) with Java’s OO style

  6. JDBC API BASIC CLASSES: • Statement Class • sends SQL statements to DBMS • Useful Methods: int executeUpdate(String sql_statement); • Used to execute DDL SQL statement, ex: creating, altering tables. ResultSet executeQuery(String sql_statement); • used to execute common SQL statements, such as SELECTs • ResultSet Class • Manipulates rows in a table • Useful Methods: beforeFirst(); //moves cursor to front of result set boolean next(); //moves the cursor to the next row • The "cursor" starts just above first row, so call next() to get to the first row

  7. JDBC API Establish Connection • Load Driver: For example: using JDBC-ODBC Bridge driver: Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver“); • Make Connection Connection con = DriverManager.GetConnection(url, "myLogin", "myPassword");

  8. JDBC API • Create Tables String makeTable = “create table Students” + "(Name varchar(32), ID integer)"; Statement stmt = con.createStatement(); stmt.executeUpdate(makeTable); • Populate Tables Statement stmt = con.createStatement() stmt.executeUpdate(“insert into students values ('Mark', 523)");

  9. JDBC API Retrieve Data String query = “select Name, ID from Students"; ResultSet rs = stmt.executeQuery(query); while(rs.next()) { String s = rs.getString("Name"); int n = rs.getInt(“ID"); }

  10. Linking Servers: Same idea extended to multiple kinds of data sources on remote servers Linking Servers

  11. PHP: Same Idea as JDBC Project 1

More Related