범용 커넥션 풀 라이브러리 : connection pool Libzdb

libzdb-3.1.tar.gz

 
Version 3.1
 

A small, easy to use Open Source Database Connection Pool Library with the following features:

  • Thread safe Database Connection Pool
  • Connect to multiple database systems
  • Zero runtime configuration, connect using a URL scheme
  • Supports MySQL, PostgreSQL, SQLite and Oracle
Libzdb API documentation

ConnectionPool URL Connection PreparedStatement ResultSet

Clickable API documentation

 

Connection URL:

The URL given to a Connection Pool at creation time specify a database connection on the standard URL format. The format of the connection URL is defined as:

database://[user:password@][host][:port]/database[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...

The property names user and password are always recognized and specify how to login to the database. Other properties depends on the database server in question. User name and password can alternatively be specified in the auth-part of the URL. If port number is omitted, the default port number for the database server is used.

MySQL:

Here is an example on how to connect to a MySQL database server:

mysql://localhost:3306/test?user=root&password=swordfish

In this case the username, root and password, swordfish are specified as properties to the URL. An alternative is to use the auth-part of the URL to specify authentication information:

mysql://root:swordfish@localhost:3306/test

See mysql options for all properties that can be set for a mysql connection URL.

SQLite:

For a SQLite database the connection URL should simply specify a database file, since a SQLite database is just a file in the filesystem. SQLite uses pragma commands for performance tuning and other special purpose database commands. Pragma syntax on the form, name=value can be added as properties to the URL and will be set when the Connection is created. In addition to pragmas, the following properties are supported:

  • heap_limit=value [KB] - Make SQLite auto-release unused memory if memory usage goes above the specified value.

An URL for connecting to a SQLite database might look like:

sqlite:///var/sqlite/test.db?synchronous=normal&heap_limit=8000&foreign_keys=on

PostgreSQL:

The URL for connecting to a PostgreSQL database server might look like:

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

postgresql://localhost:5432/test?user=root&password=swordfish

As with the MySQL URL, the username and password are specified as properties to the URL. Likewise, the auth-part of the URL can be used instead to specify the username and the password:

postgresql://root:swordfish@localhost/test?use-ssl=true

In this example we have also omitted the port number to the server, in which case the default port number, 5432, for PostgreSQL is used. In addition we have added an extra parameter to the URL, so connection to the server is done over a secure SSL connection.

See postgresql options for all properties that can be set for a postgresql connection URL.

Oracle:

The URL for connecting to an Oracle database server might look like:

oracle://localhost:1521/test?user=scott&password=tiger

The auth-part of the URL can be used instead to specify the username and the password. In addition, you may specify a service name in the URL instead if you have setup a tnsnames.ora configuration file.

oracle:///servicename?user=scott&password=tiger

Examples:

To obtain a connection pool for a MySQL database, the code below can be used. The exact same code can be used for PostgreSQL, SQLite and Oracle, the only change needed is to modify the Connection URL. Here we connect to the database test on localhost and start the pool with the default 5 initial connections.

ConnectionPool, Connection and ResultSet:

URL_T url = URL_new("mysql://localhost/test?user=root&password=swordfish");
ConnectionPool_T pool = ConnectionPool_new(url);
ConnectionPool_start(pool);

Connection_T con = ConnectionPool_getConnection(pool);
ResultSet_T result = Connection_executeQuery(con, 
                     "select id, name, image from employee where salary > %d", aNumber);
while (ResultSet_next(result)) 
{
     int id = ResultSet_getInt(result, 1);
     const char *name = ResultSet_getString(result, 2);
     int blobSize;
     const void *image = ResultSet_getBlob(result, 3, &blobSize);
     [..]
}
                

Here is another example where a generated result is selected and printed:

ResultSet_T r = Connection_executeQuery(con, "SELECT count(*) FROM users");
printf("Number of users: %s\n", ResultSet_next(r) ? ResultSet_getString(r, 1) : "no users");
                

Prepared statement:

PreparedStatement_T p = Connection_prepareStatement(con, 
                        "INSERT INTO employee(name, picture) VALUES(?, ?)");
PreparedStatement_setString(p, 1, "Kamiya Kaoru");
PreparedStatement_setBlob(p, 2, jpeg, jpeg_size);
PreparedStatement_execute(p);
               

Here, we use a Prepared Statement to execute a query which returns a Result Set:

PreparedStatement_T p = Connection_prepareStatement(con, 
                        "SELECT id FROM employee WHERE name LIKE ?"); 
PreparedStatement_setString(p, 1, "%Kaoru%");
ResultSet_T r = PreparedStatement_executeQuery(p);
while (ResultSet_next(r))
       printf("employee.id = %d\n", ResultSet_getInt(r, 1));
               

 

[출처] http://www.tildeslash.com/libzdb/#api

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86310
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78764
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95512
31 오라클 컬럼명 찾기 졸리운_곰 2017.04.17 2030
30 [Oracle | 오라클] DB 덤프/임포트 하기 졸리운_곰 2017.03.17 1230
29 Oracle Data pump 실전 사용 졸리운_곰 2017.03.17 857
28 오라클 덤프 export / import file 졸리운_곰 2017.03.17 1348
27 오라클 DB 백업과 복원 졸리운_곰 2017.03.17 1778
26 SQL HINT 를 이용하여 SQL Tunning 을 하는 방법 file 졸리운_곰 2017.03.15 1305
25 <운바-DB> Oracle HINT(기초) file 졸리운_곰 2017.03.15 1532
24 조인 순서 조정을 위한 힌트(ordered, leading) 졸리운_곰 2017.03.15 1476
23 ORACLE Hint 정리 file 졸리운_곰 2017.03.15 1725
22 Oracle Hint 설명 및 사용법 졸리운_곰 2017.03.15 1561
21 ORACLE SQL 서버 및 PLSQL 코딩 표준 가이드 file 졸리운_곰 2017.01.14 1758
20 ORACLE SQL 튜닝 가이드 file 졸리운_곰 2014.06.07 3944
19 Oracle DECODE문을 IF문처럼 사용하기. 졸리운_곰 2014.01.25 2476
18 [ORACLE] NVL함수 & DECODE함수 졸리운_곰 2014.01.25 2470
17 ※ Oracle 오라클 DECODE 함수 file 졸리운_곰 2014.01.25 2772
16 오라클 백업 및 복구(Datapump) 졸리운_곰 2014.01.25 2124
15 (Oracle) delete 복구 졸리운_곰 2014.01.25 2423
14 오라클 쿼리 복구 졸리운_곰 2014.01.25 3453
13 오라클 플래쉬백 사용하기(Flashback Query) 졸리운_곰 2014.01.25 2603
12 체크 제약조건 적용사례 졸리운_곰 2014.01.19 3169
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED