通过安装了PostgreSQL ODBC接口,然后通过OTL进行数据库的访问
代码
void TestByOtl()
{
odbc::otl_connect db;
odbc::otl_connect::otl_initialize();
try {
db.rlogon("Driver={PostgreSQL Unicode};Server=192.168.10.227;Port=5432;Database=pas;Uid=postgres;Pwd=admin12345");
odbc::otl_cursor::direct_exec(
db,
"create table student (id int, name varchar(30))"
);
odbc::otl_cursor::direct_exec(
db,
"insert into student values(31090012, 'fengyuzaitu@126.com')"
);
}
catch (odbc::otl_exception& p) { // 捕获OTL异常
cerr << p.msg << endl; // 打印错误信息
cerr << p.stm_text << endl; // 打印引起错误的SQL语句
cerr << p.sqlstate << endl; // 打印引起错误的SQL状态
cerr << p.var_info << endl; // 打印引起错误的变量
}
db.logoff();
}