源代码
C++代码
1. #include <iostream>
2. #include <string>
3. #include "occi.h"
4. using namespace oracle::occi;
5. using namespace std;
6.
7. int main()
8. {
9. string usr="sys";
10. string pwd="orcl";
11. string SID="ORCL"; //注意大小写
12. string date;
13.
14. Environment *env=Environment::createEnvironment(Environment::OBJECT);
15. Connection *conn= env->createConnection(usr,pwd,SID);//all strings
16. if(conn)
17. cout<<"success createConnection!"<<endl;
18. else
19. cout<<"failure createConnection!"<<endl;
20.
21. Statement *stmt = conn->createStatement();
22. string sSQL = "select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual";
23. stmt->setSQL(sSQL);
24.
25.
26. ResultSet *rs = stmt->executeQuery();
27. if(rs->next())
28. {
29. date = rs->getString(1);
30. }
31.
32. cout<<"now time :"<<date<<endl;
33.
34. env->terminateConnection(conn);
35. Environment::terminateEnvironment(env);
36.
37. linux安装数据库 return 0;
38. }
39.
#include <iostream>
#include <string>
#include "occi.h"
using namespace oracle::occi;
using namespace std;
int main()
{
string usr="sys";
string pwd="orcl";
string SID="ORCL";
string date;
Environment *env=Environment::createEnvironment(Environment::OBJECT);
Connection *conn= env->createConnection(usr,pwd,SID);//all strings
if(conn)
cout<<"success createConnection!"<<endl;
else
cout<<"failure createConnection!"<<endl;
Statement *stmt = conn->createStatement();
string sSQL = "select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual";
stmt->setSQL(sSQL);
ResultSet *rs = stmt->executeQuery();
if(rs->next())
{
date = rs->getString(1);
}
cout<<"now time :"<<date<<endl;
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
return 0;
}
我linux上安装oracle路径:/u01/app/oracle/product/10.2.0/db_1
编译命令:g++ -o conn -L/u01/app/oracle/product/10.2.0/db_1/lib -L/u01/oracle/product/10.2.0/db_1/rdbms/lib conn_db.cpp
问题一:编译时报如下错误:
Shell代码
1. [oracle@localhost demo]$ g++ -o conn -L/u01/app/oracle/product/10.2.0/db_1/lib -L/u01/oracle/product/10.2.0/db_1/rdbms/lib conn_db.cpp
2. g++: g++: No such file or directory
3. conn_db.cpp:3:18: error: occi.h: No such file or directory
4. conn_db.cpp:4: error: 'oracle' has not been declared
5. conn_db.cpp:4: error: 'occi' is not a namespace-name
6. conn_db.cpp:4: error: expected namespace-name before ';' token
7. conn_db.cpp: In function 'int main()':
8. conn_db.cpp:14: error: 'Environment' was not declared in this scope
9. conn_db.cpp:14: error: 'env' was not declared in this scope
10. conn_db.cpp:14: error: 'Environment' is not a class or namespace
11. conn_db.cpp:14: error: 'Environment' is not a class or namespace
12. conn_db.cpp:15: error: 'Connection' was not declared in this scope
13. conn_db.cpp:15: error: 'conn' was not declared in this scope
14. conn_db.cpp:21: error: 'Statement' was not declared in this scope
15. conn_db.cpp:21: error: 'stmt' was not declared in this scope
16. conn_db.cpp:26: error: 'ResultSet' was not declared in this scope
17. conn_db.cpp:26: error: 'rs' was not declared in this scope
18. conn_db.cpp:35: error: 'Environment' is not a class or namespace
19.
[oracle@localhost demo]$ g++ g++ -o conn -L/opt/app/oracle/product/10.2.0/db_1/lib -L/opt/oracle/product/10.2.0/db_1/rdbms/lib -lclntsh -locci /usr/lib/libstdc++.so.5 conn_db.cpp -g
g++: g++: No such file or directory
conn_db.cpp:3:18: error: occi.h: No such file or directory
conn_db.cpp:4: error: 'oracle' has not been declared
conn_db.cpp:4: error: 'occi' is not a namespace-name
conn_db.cpp:4: error: expected namespace-name before ';' token
conn_db.cpp: In function 'int main()':
conn_db.cpp:14: error: 'Environment' was not declared in this scope
conn_db.cpp:14: error: 'env' was not declared in this scope
conn_db.cpp:14: error: 'Environment' is not a class or namespace
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论