ÀÌ »ùÇà ÇÁ·Î±×·¥Àº ´ÙÀ½°ú °°Àº Áö¿ø ¾ð¾î·Î Á¤Àû SQL¹® ¹× µ¥ÀÌÅͺ£À̽º °ü¸® ÇÁ·Î±×·¥ API È£ÃâÀÇ ¿¹¸¦ º¸¿© ÁÝ´Ï´Ù.
REXX ¾ð¾î´Â Á¤Àû SQLÀ» Áö¿øÇÏÁö ¾ÊÀ¸¹Ç·Î »ùÇÃÀº Á¦°øµÇÁö ¾Ê½À´Ï´Ù.
ÀÌ »ùÇà ÇÁ·Î±×·¥¿¡´Â ´ÜÀÏ ÇàÀ» ¼±ÅÃÇÏ´Â Á¶È¸°¡ Æ÷ÇԵǾî ÀÖ½À´Ï´Ù. ÀÌ·¯ÇÑ Á¶È¸´Â SELECT INTO¹®À» »ç¿ëÇÏ¿© ¼öÇàÇÒ ¼ö ÀÖ½À´Ï´Ù.
SELECT INTO¹®Àº µ¥ÀÌÅͺ£À̽ºÀÇ Å×ÀÌºí¿¡¼ ÇÑ ÇàÀÇ µ¥ÀÌÅ͸¦ ¼±ÅÃÇϰí, ÀÌ ÇàÀÇ °ªµéÀº ¸í·É¹®¿¡ ÁöÁ¤µÈ È£½ºÆ® º¯¼ö¿¡ ÁöÁ¤µË´Ï´Ù. È£½ºÆ® º¯¼ö¿¡ ´ëÇØ¼´Â È£½ºÆ® º¯¼ö »ç¿ë¿¡ »ó¼¼È÷ ³íÀǵǾî ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î, ´ÙÀ½ ¸í·É¹®Àº ¼ºÀÌ 'HAAS'ÀÎ »ç¿øÀÇ ±Þ¿©¸¦ empsal È£½ºÆ® º¯¼ö·Î Àü´ÞÇÕ´Ï´Ù.
SELECT SALARY INTO :empsal FROM EMPLOYEE WHERE LASTNAME='HAAS'
SELECT INTO¹®Àº ÇÑ Çุ ¸®ÅÏÇϵµ·Ï ÁöÁ¤ÇØ¾ß ÇÕ´Ï´Ù. ÇÑ Çà ÀÌ»óÀ» ¹ß°ßÇÏ¸é ¿À·ù, SQLCODE -811(SQLSTATE 21000)ÀÌ ¹ß»ýÇÕ´Ï´Ù. Á¶È¸ °á°ú ¿©·¯ ÇàÀÌ ³ª¿Ã °æ¿ì Ä¿¼¸¦ »ç¿ëÇÏ¿© ÇàÀ» ó¸®ÇØ¾ß ÇÕ´Ï´Ù. Ä¿¼¸¦ ÀÌ¿ëÇÑ ´ÙÁß Çà ¼±Åÿ¡¼ ÀÚ¼¼ÇÑ ³»¿ëÀ» ÂüÁ¶ÇϽʽÿÀ.
SELECT INTO¹®¿¡ ´ëÇÑ ¼¼ºÎ»çÇ×Àº SQL ÂüÁ¶¼ÀÇ ³»¿ëÀ» ÂüÁ¶ÇϽʽÿÀ.
SELECT¹® ÀÛ¼º ¹æ¹ý¿¡ ´ëÇÑ ¼Ò°³´Â µ¥ÀÌÅÍ °Ë»ö ¹× Á¶ÀÛ¿ë SQL¹® ÄÚµùÀÇ ³»¿ëÀ» ÂüÁ¶ÇϽʽÿÀ.
ÀÌ ¿À·ù üũ À¯Æ¿¸®Æ¼¿¡ ´ëÇÑ ¼Ò½º Äڵ忡 ´ëÇØ¼´Â ¿¹Á¦ ÇÁ·Î±×·¥¿¡¼ GET ERROR MESSAGE »ç¿ëÀÇ ³»¿ëÀ» ÂüÁ¶ÇϽʽÿÀ.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "utilemb.h" EXEC SQL INCLUDE SQLCA; (1) int main(int argc, char *argv[]) { int rc = 0; char dbAlias[15] ; char user[15] ; char pswd[15] ; EXEC SQL BEGIN DECLARE SECTION; (2) char firstname[13]; EXEC SQL END DECLARE SECTION; /* checks the command line arguments */ rc = CmdLineArgsCheck1( argc, argv, dbAlias, user, pswd ); (3) if ( rc != 0 ) return( rc ) ; printf("\n\nSample C program: STATIC\n"); /* initialize the embedded application */ rc = EmbAppInit( dbAlias, user, pswd); if ( rc != 0 ) return( rc ) ; EXEC SQL SELECT FIRSTNME INTO :firstname (4) FROM employee WHERE LASTNAME = 'JOHNSON'; EMB_SQL_CHECK("SELECT statement"); (5) printf( "First name = %s\n", firstname ); /* terminate the embedded application */ rc = EmbAppTerm( dbAlias); return( rc ) ; } /* end of program : STATIC.SQC */
import java.sql.*; import sqlj.runtime.*; import sqlj.runtime.ref.*; class Static { static { try { Class.forName ("COM.ibm.db2.jdbc.app.DB2Driver").newInstance (); } catch (Exception e) { System.out.println ("\n Error loading DB2 Driver...\n"); System.out.println (e); System.exit(1); } } public static void main(String argv[]) { try { System.out.println (" Java Static Sample"); String url = "jdbc:db2:sample"; // URL is jdbc:db2:dbname Connection con = null; // Set the connection (3) if (argv.length == 0) { // connect with default id/password con = DriverManager.getConnection(url); } else if (argv.length == 2) { String userid = argv[0]; String passwd = argv[1]; // connect with user-provided username and password con = DriverManager.getConnection(url, userid, passwd); } else { throw new Exception("\nUsage: java Static [username password]\n"); } // Set the default context DefaultContext ctx = new DefaultContext(con); DefaultContext.setDefaultContext(ctx); String firstname = null; #sql { SELECT FIRSTNME INTO :firstname FROM employee WHERE LASTNAME = 'JOHNSON' } ; (4) System.out.println ("First name = " + firstname); } catch( Exception e ) (5) { System.out.println (e); } } }
Identification Division. Program-ID. "static". Data Division. Working-Storage Section. copy "sql.cbl". copy "sqlca.cbl". (1) EXEC SQL BEGIN DECLARE SECTION END-EXEC. (2) 01 firstname pic x(12). 01 userid pic x(8). 01 passwd. 49 passwd-length pic s9(4) comp-5 value 0. 49 passwd-name pic x(18). EXEC SQL END DECLARE SECTION END-EXEC. 77 errloc pic x(80). Procedure Division. Main Section. display "Sample COBOL program: STATIC". display "Enter your user id (default none): " with no advancing. accept userid. if userid = spaces EXEC SQL CONNECT TO sample END-EXEC else display "Enter your password : " with no advancing accept passwd-name. * Passwords in a CONNECT statement must be entered in a VARCHAR format * with the length of the input string. inspect passwd-name tallying passwd-length for characters before initial " ". EXEC SQL CONNECT TO sample USER :userid USING :passwd (3) END-EXEC. move "CONNECT TO" to errloc. call "checkerr" using SQLCA errloc. EXEC SQL SELECT FIRSTNME INTO :firstname (4) FROM EMPLOYEE WHERE LASTNAME = 'JOHNSON' END-EXEC. move "SELECT" to errloc. call "checkerr" using SQLCA errloc. (5) display "First name = ", firstname. EXEC SQL CONNECT RESET END-EXEC. (6) move "CONNECT RESET" to errloc. call "checkerr" using SQLCA errloc. End-Prog. stop run.