Connection Pooling: Objects and Will Keep Them in A Separate Base Object Called Pool Object

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Connection pooling

When we have requirement to perform database operations we will establish the connection with the
database from java application, at the end of the application we will close the connection i.e destroying
connection object.

In jdbc applications, every time establishing the connection and closing the connection may increase
burden to jdbc application, it will reduce the performance of the jdbc application. In the above context,
to improve the performance of jdbc applications we will use an alternative called as connection pooling.

In connection pooling at the time of application startup we will prepare a fixed number of connection
objects and will keep them in a separate base object called Pool object.

In jdbc application, when we have a requirement to interact with the database then we will get the
connection object from pool object and we will assign it to the respective client application.

Implementation of connection pooling:


To implement connection pooling create table in database with columns id, name, salary, etc.

Meta Data
Definition: Data about data is called Meta-Data. Two types:

1. DatabaseMetaData
2. ResultSetMetaData

1. DatabaseMetaData
Database name, database product version, driver version, supported sql keywords, string
function, number function…etc.

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;

public class MyMetaData {

public static void main(String[] args) throws Exception{

Connection con = null;


DatabaseMetaData md = null;
try {
Class.forName("oracle.jdbc.OracleDriver");
con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "system",
"system");
md= con.getMetaData();
System.out.println(md.getDatabaseProductName());
System.out.println(md.getDatabaseProductVersion());
System.out.println(md.getDriverMajorVersion());
System.out.println(md.getDriverMinorVersion());
System.out.println(md.getSQLKeywords());
System.out.println(md.getStringFunctions());
System.out.println(md.getNumericFunctions());
System.out.println(md.getDatabaseProductName());
System.out.println(md.supportsBatchUpdates());
System.out.println(md.getDatabaseProductName());
System.out.println(md.supportsStoredProcedures());
} catch (Exception e) {
e.printStackTrace();
}
finally {
try {
con.close();
}

catch (Exception e1) {


e1.printStackTrace();
}
}
}
}
Output:

Oracle
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
10
2

ACCESS, ADD, ALTER, AUDIT, CLUSTER, COLUMN, COMMENT, COMPRESS, CONNECT, DATE, DROP,
EXCLUSIVE, FILE, IDENTIFIED, IMMEDIATE, INCREMENT, INDEX, INITIAL, INTERSECT, LEVEL,
LOCK, LONG, MAXEXTENTS, MINUS, MODE, NOAUDIT, NOCOMPRESS, NOWAIT, NUMBER, OFFLINE,
ONLINE, PCTFREE, PRIOR, all_PL_SQL_reserved_ words

ASCII,CHAR,CONCAT,LCASE,LENGTH,LTRIM,REPLACE,RTRIM,SOUNDEX,SUBSTRING,UCASE

ABS,ACOS,ASIN,ATAN,ATAN2,CEILING,COS,EXP,FLOOR,LOG,LOG10,MOD,PI,POWER,ROUND,SIGN,SIN,
SQRT,TAN,TRUNCATE
Oracle
true
Oracle
True

2. ResultSetMetaData
Data about resultset is called resultsetmetadata, it includes no. of columns,columns
name,columns datatypes, column sizes etc.
Public ResultSetMetaData getMetaData()

You might also like