当前位置: 技术问答>linux和unix
请教:如何在unix下用c开发连接oracle数据库。
来源: 互联网 发布时间:2016-01-02
本文导语: 请教如题 望大侠指点,谢谢了,急在线等 | 用E SQL 写一套底层就可以了啊 连接, 插入、删除、查询 断开连接 做成函数库 | oracle提供了C接口呀,具体你还是找本书或者ora...
请教如题
望大侠指点,谢谢了,急在线等
望大侠指点,谢谢了,急在线等
|
用E SQL 写一套底层就可以了啊
连接,
插入、删除、查询
断开连接
做成函数库
连接,
插入、删除、查询
断开连接
做成函数库
|
oracle提供了C接口呀,具体你还是找本书或者oracle的资料看看吧
|
用pro*c吧
|
int ConnectDb(char *p_user, char *p_pswd, char *p_server)
{
EXEC SQL BEGIN DECLARE SECTION;
char sDbNameAndPawd[80];
char sDbServerName[30];
EXEC SQL END DECLARE SECTION;
memset(sDbNameAndPawd, 0, sizeof(sDbNameAndPawd));
memset(sDbServerName, 0, sizeof(sDbServerName));
sprintf(sDbNameAndPawd, "%s/%s", p_user, p_pswd);
sprintf(sDbServerName, "%s", p_server);
if (memcmp(p_server, "NULL", 4) == 0) //如果为本地连接,服务器名设置为空
{
EXEC SQL CONNECT :sDbNameAndPawd;
}
else
{
EXEC SQL CONNECT :sDbNameAndPawd using :sDbServerName;
}
if(sqlca.sqlcode != 0)
{
return -1;
}
else
{
return 0;
}
}
{
EXEC SQL BEGIN DECLARE SECTION;
char sDbNameAndPawd[80];
char sDbServerName[30];
EXEC SQL END DECLARE SECTION;
memset(sDbNameAndPawd, 0, sizeof(sDbNameAndPawd));
memset(sDbServerName, 0, sizeof(sDbServerName));
sprintf(sDbNameAndPawd, "%s/%s", p_user, p_pswd);
sprintf(sDbServerName, "%s", p_server);
if (memcmp(p_server, "NULL", 4) == 0) //如果为本地连接,服务器名设置为空
{
EXEC SQL CONNECT :sDbNameAndPawd;
}
else
{
EXEC SQL CONNECT :sDbNameAndPawd using :sDbServerName;
}
if(sqlca.sqlcode != 0)
{
return -1;
}
else
{
return 0;
}
}
|
用比如Pro*C、ESQL/C这样的嵌入式sql简直是自杀式行为。Oracle提供的oci/c++库就是为了消灭proc。不知informix有没有类似的库用于消灭esqlc。
OCCI provides a library of standard database access and retrieval functions in the
form of a dynamic runtime library (OCCI classes) that can be linked in a C++
application at runtime. This eliminates the need to embed SQL or PL/SQL within
third-generation language (3GL) programs.
Oracle C++ Call Interface Programmers Guide
a96583.pdf
OCCI provides a library of standard database access and retrieval functions in the
form of a dynamic runtime library (OCCI classes) that can be linked in a C++
application at runtime. This eliminates the need to embed SQL or PL/SQL within
third-generation language (3GL) programs.
Oracle C++ Call Interface Programmers Guide
a96583.pdf