cplusplus
用C++库连接Oracle, MS SQL, MySQL等数据库
上一篇 /
下一篇 2012-08-11 20:58:29
/ 个人分类:转载
最近在网上找到一个好东西SQLAPI++,它是可以访问多个SQL数据库(Oracle, SQL Server, DB2, Sybase, Informix, InterBase, SQLBase, MySQL, PostgreSQL)C++库。SQLAPI++直接调用本地目标数据库管理系统(DBMS)的API(不像ADO一样使用OLEDB and/or ODBC 中间层)。SQLAPI++库扮演了一个中间件以间接方便访问数据库的角色,这就是为什么SQLAPI++是访问数据库最快的方法。在开发和发布您的应用程序时不再需要安装和配置OLEDB and/or ODBC的驱动。SQLAPI支持的开发平台有Microsoft Visual C++,Borland C++ Builder,Gun Project C and C++ Compiler。示例代码如下:#include <stdio.h> #include <SQLAPI.h> int main(int argc, char* argv[]){ SAConnection con; SACommand cmd( &con, "Select fid, fvarchar20 from test_tbl"); // 本文转自 C++Builder 研究 - http://www.ccrun.com/article.asp?i=1020&d=ssoqrd try { con.Connect("test", "tester", "tester", SA_Oracle_Client); cmd.Execute(); while(cmd.FetchNext()) { printf("Row fetched: fid = %ld, fvarchar20 = '%s'\n", cmd.Field("fid").asLong(), (const char*)cmd.Field("fvarchar20").asString()); } con.Commit(); printf("Rows selected!\n"); } catch(SAException &x) { try { con.Rollback(); } catch(SAException &) { } printf("%s\n", (const char*)x.ErrText()); } return 0;}SQLAPI++的官方网站是www.sqlapi.com,它提供评估版本给客户测试。可惜评估版本的库文件在连接数据库成功后,会弹出一个MessageBox对话框。我在测试它的时候觉得很烦,便把它破解掉了,如果需要可以到我的个人网站去下载它www.szsmart.net,不过只提供BCB的破解版本。
收藏
举报
TAG:
DataBase
database
DATABASE