1 / 9

E-Genting Programming Competition 2004

E-Genting Programming Competition 2004. Pre-Competition Workshop, Week 1 21 September 2004. Workshop Outline. Embedded SQL Data Flows. Interactive Query. Entered query : select custName from custFile where custId = 100127 Displayed result: custName JOE BLOGS. Embedded SQL Statement.

jola
Download Presentation

E-Genting Programming Competition 2004

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. E-Genting Programming Competition 2004 Pre-Competition Workshop, Week 1 21 September 2004

  2. Workshop Outline

  3. Embedded SQL Data Flows

  4. Interactive Query Entered query: select custName from custFile where custId = 100127 Displayed result: custName JOE BLOGS

  5. Embedded SQL Statement exec sql begin declare section; char nameVar[41]; // Customer name variable long idVar; // Customer id variable exec sql end declare section; // ... idVar = 100127; exec sql select custName into :nameVar from custFile where custId = :idVar; if (SQLCODE != 0) {/* process row not found error */} cout << "Customer name is " << nameVar << '\n';

  6. JDBC Method Calls Statement stmt; // JDBC statement ResultSet rs; // JDBC result set int idVar; // Customer id variable String nameVar; // Customer name variable //... idVar = 100127; rs = stmt.executeQuery ( "select custName from custFile" + "where custId = " + idVar ); if ( ! rs.next()) {/* process row not found error */} nameVar = rs.getString ("custName"); System.out.println ("Customer name is " + nameVar);

  7. Errors that an embedded SQL pre-processor can detect at compile time that raw JDBC calls cannot detect until run time: incorrectly spelled reserved words such as ‘select’ and ‘where’; syntax errors in SQL statements; misspelled column names; ambiguous column names (i.e. a reference to an unqualified column name that is a valid column name in two tables in the query); incompatible database column and host variable data types.

  8. Cursor Select exec sql declare custCur cursor for select custId, custName from custFile; exec sql open custCur; for (;;) { exec sql fetch custCur into :idVar, :nameVar; if (SQLCODE != 0) break; cout << idVar << " " << nameVar << '\n'; } exec sql close custCur;

  9. Formalities exec sql include sqlca; //... int main () { //... exec sql connect to 'custDb'; //... } Alternatively, in the competition: // Insert statement to connect to the // database here.

More Related