1. 程式人生 > 其它 >ocilib庫遠端連線區域網中其它伺服器上的資料庫

ocilib庫遠端連線區域網中其它伺服器上的資料庫

技術標籤:ocilib開源庫OCILIB遠端連線

1、使用ocilib連線區域網中其它資料庫的時候,不需要建立本地服務,只需在con變數建立的時候加上要連線資料庫所在伺服器的ip地址即可。當然資料庫所在的伺服器要配置好監聽。

2、例項:

int _tmain(int argc, _TCHAR* argv[])
{
	try
	{
		Environment::Initialize(Environment::Default | Environment::Threaded);
		Environment::EnableWarnings(true);
		Connection con("192.168.20.214/orcl", "scott", "tiger");
		Statement st(con);

		if (con.IsServerAlive())
		{
			std::cout << "1234567890" << std::endl;
		}
		
		st.SetFetchMode(Statement::FetchScrollable);
		st.Execute("select *from dept");

		Resultset rs = st.GetResultset();
		rs.Last();
		std::cout << "一共有多少行資料: " << rs.GetCount() << std::endl;

		rs.First();
		std::cout << rs.Get<ostring>(1) << "--" << rs.Get<ostring>(2) << "--" << rs.Get<ostring>(3) << rs.Get<Date>(3).ToString("YYYY-MM-DD HH24:MI:SS") << std::endl;
		while (rs++)
		{
			std::cout << rs.Get<ostring>(1) << "--" << rs.Get<ostring>(2) << "--" << rs.Get<ostring>(3) << rs.Get<Date>(3).ToString("YYYY-MM-DD HH24:MI:SS") << std::endl;
		}

		if (con) con.Close();
	}
	catch (std::exception &ex)
	{
		std::cout << ex.what() << std::endl;
	}
	Environment::Cleanup();
	system("pause");
	return 0;
}

3、因為沒有配置本地服務:我們在使用PL/SQL Developer連線的時候,不能連線成功: