Hello, I am using libzdb for database connection pool from a C++ program . Till now I was making only one database connection pool through libzdb and was working perfect . Now I need to make multiple database connection pools , I tried making this , but it consider only one connection pool and fetch the data from only one database . I found that Multiple database connection is possible through libzdb , somehow I am not able to do that . Any help will be appriciated.
Thank You,Ravi
The following _un-tested_ code demonstrate how to use two different connection pools
// MySQL Connection Pool ConnectionPool_T myPool = ConnectionPool_new(URL_new("mysql://root:swordfish@localhost:3306/test")); ConnectionPool_start(myPool);
// Postgres Connection Pool ConnectionPool_T pgPool = ConnectionPool_new(URL_new("postgresql://root:swordfish@localhost/test")); ConnectionPool_start(pgPool);
// MySQL Connection Connection_T mc = ConnectionPool_getConnection(myPool); // Postgres Connection Connection_T pc = ConnectionPool_getConnection(pgPool);
// Select from MySQL and Prepare to insert into Postgres ResultSet_T r = Connection_executeQuery(mc, "select id, name from employee”); PreparedStatement_T p = Connection_prepareStatement(pc, "INSERT INTO employee(id, name) VALUES(?, ?)”);
while (ResultSet_next(r)) { // Select from MySQL int id = ResultSet_getInt(r, 1); const char *name = ResultSet_getString(r, 2);
// Insert into Postgres PreparedStatement_setInt(p, 1, id); PreparedStatement_setString(p, 2, name); PreparedStatement_execute(p); }
[..]
// Close URL_T myURL = ConnectionPool_getURL(myPool); ConnectionPool_free(&myPool); URL_free(&myURL);
URL_T pgURL = ConnectionPool_getURL(pgPool); ConnectionPool_free(&pgPool); URL_free(&pgURL);
On 12 Aug 2015, at 08:14, patel ravi patel_ravij@yahoo.com wrote:
Hello, I am using libzdb for database connection pool from a C++ program . Till now I was making only one database connection pool through libzdb and was working perfect . Now I need to make multiple database connection pools , I tried making this , but it consider only one connection pool and fetch the data from only one database . I found that Multiple database connection is possible through libzdb , somehow I am not able to do that . Any help will be appriciated.
Thank You, Ravi