📄 insert1.c
字号:
/* Copyright (c) 2004, 2005, Oracle. All rights reserved. *//* NAME insert1.c - <one-line expansion of the name> DESCRIPTION <short description of facility this file declares/defines> EXPORT FUNCTION(S) <external functions defined for use outside package - one-line descriptions> INTERNAL FUNCTION(S) <other external functions defined - one-line descriptions> STATIC FUNCTION(S) <static functions defined - one-line descriptions> NOTES <other useful comments, qualifications, etc.> MODIFIED (MM/DD/YY) ardesai 03/04/05 - Include windows.h for windows platform. subanerj 06/06/04 - subanerj_odbc_env_setup ardesai 06/02/04 - Creation*/#ifdef WIN32COMMON#include <windows.h>#endif#include <stdio.h>#include <sql.h>#include <sqlext.h>#define STR_LEN 30int main(){ HENV henv; /* environment handle */ HDBC hdbc; /* connection handle */ HSTMT hstmt; /* statement handle */ SDWORD retcode; /* return code */ SQLCHAR *stmt ="insert into myemp(empno, sal) values (953,8989)"; SQLCHAR ename[40]="Rama"; SQLUINTEGER empno=111, sal=2222; SQLINTEGER enameInd, salInd, enoInd; SQLCHAR SqlState[6], Msg[SQL_MAX_MESSAGE_LENGTH]; SQLINTEGER NativeError; SQLSMALLINT MsgLen; retcode = SQLAllocEnv(&henv); retcode = SQLAllocConnect(henv, &hdbc); retcode = SQLConnect(hdbc, "TestDBDSN", SQL_NTS, "scott", SQL_NTS, "tiger", SQL_NTS); retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); if ((retcode = SQLPrepare(hstmt, stmt, SQL_NTS)) != SQL_SUCCESS) goto EXIT; if ((retcode = SQLExecute(hstmt)) != SQL_SUCCESS) goto EXIT; SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT);EXIT: if (retcode != SQL_SUCCESS) { if((retcode = SQLGetDiagRec( SQL_HANDLE_DBC, hdbc, 1, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen ) ) != SQL_NO_DATA ) printf("SqlState = %s\n Message = %s\n", SqlState, Msg); } SQLFreeStmt(hstmt, SQL_CLOSE); SQLDisconnect(hdbc); SQLFreeConnect(hdbc); SQLFreeEnv(henv); return 1;}/* end of file insert1.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -