ASSIGNMENT 7
EXERCISE 5
Stefan Lederer | 0761467
Exercise 5
Use the given source code below for real
tests and identification of performance
bottlenecks. Write a small test program
and call update within loops several
times.
Questions:
Provide your test cases and also some
performance measures.
Identify bottlenecks and fix them.
Compare your solution(s) to the given
one.
Performance measures
long milliStart;
long milliEnd;
milliStart = System.currentTimeMillis();
milliEnd = System.currentTimeMillis();
}catch(Exception e){
System.err.println("Error: " + e.getMessage());
}
}
Queries
Select
Select
* from country where population > 0
and population < 50 000
Update
updatecountry set area = 80000,
population = 8000000 where code = 'A'
Update
UPDATE TESTS
__________________________
Starting...
Execution Query 1...
Execution Query 2...
Execution Query 3...
Execution Query 4...
Execution Query 5...
Execution Query 6...
Execution Query 7...
Execution Query 8...
Execution Query 9...
Execution Query 10...
Used time: 14102 milli-sec
Select
SELECT TESTS
__________________________
Starting...
Execution Query 1...
Execution Query 2...
Execution Query 3...
Execution Query 4...
Execution Query 5...
Execution Query 6...
Execution Query 7...
Execution Query 8...
Execution Query 9...
Execution Query 10...
Used time: 13564 milli-sec
Bottlenecks
Creating/Close the connection each time
Create
the connection at the begining,
update the stuff and close it afterwards
No use of prepared Statements
Prepared statements are faster
It is given an SQL statement when it is
created
This SQL statement is sent to the DBMS
right away, where it is compiled
Use of SQL statement that has been
precompiled
Connection at beginning
try{
Connection con = DriverManager.getConnection(dburl, user,
for(int i = 0; i<NUM_LOOPS; i++){
System.out.println("Execution Query " + (i+1) + "...
exec(sql, con);
}
con.close();
}catch(Exception e){
System.err.println("Error: " + e.getMessage());
}
Pooled connections
instance represents a single physical
connection to a database
remaining open during use by a series of
logical connection instances
Logical Connection
It‘s a simple connection instance returned by a
pooled connection instance
logical connection instance acts as a temporary
handle to the physical connection
Connection Pooling - Code
OracleConnectionPoolDataSource ocpds = new
OracleConnectionPoolDataSource();
ocpds.setDriverType("oci");
ocpds.setServerName("dlsun999"); ocpds.setNetworkProtocol("tcp");
ocpds.setDatabaseName("816");
ocpds.setPortNumber(1521);
ocpds.setUser("scott");
ocpds.setPassword("tiger");
PooledConnection pc = ocpds.getPooledConnection();