In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Before reading this article, please read and understand the compilation and deployment of unixODBC/freetds. In addition, some of the data used in the following code comes from the article.
If you need to verify the part of the code, you can revise only part of the content (data source, user name, password, insert statement, etc.).
1. Test the source code
* # include # include SQLHDBC handlestmt; SQLHENV handleenv; SQLHDBC handlehdbc; bool ConnectDB () {long nRetState= 0; nRetState=SQLAllocHandle (SQLHANDLEENV,SQLNULLHANDLE,&handleenv); if ((nRetState! = SQLSUCCESS) & & (nRetState! = SQLSUCCESSWITHINFO)) return false; nRetState=SQLSetEnvAttr (handleenv, SQLATTRODBCVERSION, (void) SQLOVODBC3, 0) If ((nRetState! = SQLSUCCESS) & & (nRetState! = SQLSUCCESSWITHINFO)) return false; nRetState = SQLAllocHandle (SQLHANDLEDBC, handleenv, & handlehdbc); if ((nRetState! = SQLSUCCESS) & & (nRetState! = SQLSUCCESSWITHINFO) return false; SQLSetConnectAttr (handlehdbc, SQLLOGINTIMEOUT, (SQLPOINTER) 5,0) NRetState = SQLConnect (handlehdbc, (SQLCHAR) "odbc", SQLNTS, / / data source (SQLCHAR) "sa", SQLNTS / / user name (SQLCHAR) "root", SQLNTS) / / password if ((nRetState! = SQLSUCCESS) & & (nRetState! = SQLSUCCESSWITHINFO) return false; printf ("DB Connected!\ n"); return true;} bool InsertDB (SQLCHAR szSqlCmd) {long nRetState= 0; nRetState=SQLAllocHandle (SQLHANDLESTMT, handlehdbc, & handlestmt); if ((nRetState! = SQLSUCCESS) & & (nRetState! = SQLSUCCESSWITHINFO) return false NRetState=SQLExecDirect (handlestmt,szSqlCmd,SQLNTS); if ((nRetState! = SQLSUCCESS) & & (nRetState! = SQLSUCCESSWITHINFO) return false; printf ("InsertDB Success\ n"); return true;} bool CloseDB () {SQLFreeHandle (SQLHANDLESTMT,handlestmt); SQLDisconnect (handlehdbc); SQLFreeHandle (SQLHANDLEDBC,handlehdbc); SQLFreeHandle (SQLHANDLEENV, handleenv) Printf ("Excute Finished!\ n"); return true;} int main (int argc,char argv []) {char pSQLCommond = "insert into ReportServer.dbo.userTmp (ID) values (99)"; SQLCHAR pSQLCommondExe = (SQLCHAR) pSQLCommond; if (ConnectDB ()) {InsertDB (pSQLCommondExe); CloseDB ();} return (0);}
*
2, cross compilation
Note: cross-compilation allows links to odbc dynamic libraries.
3, deployment
Copy the compiled file to any location in the powerpc device, use chmod 755 * to add execution permissions to the compiled file, and link the odbc library to / usr/lib.
4, test and verify
The following execution result is received, which indicates that the database operation is successful. Note: it should be executed under the User user.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.