범용 커넥션 풀 라이브러리 : 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 86308
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78763
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95509
32 Apply 함수 (데이터 조작) 졸리운_곰 2017.11.02 1542
31 R apply 계열 함수 총 정리 1 ( apply / lapply / sapply / vapply ) file 졸리운_곰 2017.11.02 1069
30 R 실습 학습 2017-10-28 레슨4: 데이터 시각화 졸리운_곰 2017.10.28 1568
29 R 실습 학습 2017-10-28 레슨3 : 데이터 전처리 졸리운_곰 2017.10.28 1323
28 R 실습 학습 2017-10-26 레슨2 : 데이터 입출력 및 기초통계 졸리운_곰 2017.10.27 1446
27 R 실습 학습 2017-10-26 레슨1 졸리운_곰 2017.10.26 1456
26 R의 데이터 타입 졸리운_곰 2017.10.10 1646
25 Web-Scraping-with-R-XiaoNan.pdf file 졸리운_곰 2017.05.30 2147
24 fasttrack Web Scraping with R.pdf ​ file 졸리운_곰 2017.05.30 2175
23 R : odbc를 사용하여 MSSQL 접속 졸리운_곰 2017.05.07 1288
22 Web scraping in R: A tutorial using Super Bowl Data 졸리운_곰 2017.05.06 1127
21 R을 활용한 데이터 분석 #3 –재현성과 실행 가능성 file 졸리운_곰 2017.03.05 1324
20 R을 활용한 데이터 분석 #2 실제 분석 과정 file 졸리운_곰 2017.03.05 1692
19 R을 활용한 데이터 분석 #1 – R, 그것이 알고 싶다! file 졸리운_곰 2017.03.05 1330
18 R and Google Map Making 졸리운_곰 2017.02.21 735
17 R기초교육자료.pdf file 졸리운_곰 2017.02.21 1504
16 R 실습 예제 .pdf file 졸리운_곰 2017.02.21 1964
15 R을 이용한 부동산 데이터 분석 케이스 스터디.pdf file 졸리운_곰 2017.02.21 1325
14 R을-이용한-데이터-분석SKP배포v3_1.pdf file 졸리운_곰 2017.01.29 1517
13 R을 이용한 데이터 분석 실무.pdf file 졸리운_곰 2017.01.29 1667
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED