create table user_info ( user_id int not null primary key, user_name varchar2(100) ); //AddOcci.cc #include <iostream> #include <string> #include <occi.h> #pragma comment(lib,"oci.lib") #pragma comment(lib,"ociw32.lib") #pragma comment(lib,"oraocci10.lib") using namespace std; using namespace oracle::occi; /******************************* *******************************/ int main() { //创建环境变量 //Environment Environment *env = Environment::createEnvironment(Environment::OBJECT); //username是oracle的用户名 //userpass是oracle的密码 //connstr是oracle的连接字符串 string username = "hahaya"; string userpass = "hahaya"; string connstr = "192.168.0.6:1521/orcl"; //创建连接 //connection Connection *conn = env->createConnection(username, userpass, connstr); if(conn == NULL) { cout << "access oracle failed..." << endl; return 0; } //创建一个SQL语句的执行对象 //statement Statement *st = conn->createStatement(); st->setSQL("insert into user_info values(1, 'hahaya')"); st->executeUpdate(); //关闭连接 env->terminateConnection(conn); Environment::terminateEnvironment(env); return 0; } |