java - Time of connection to DB using JDBC -


When I check the time run like this, my machine time is 735 < / P> public class testdcp {static {try {class.forName ("com.mysql.jdbc.Driver"); } Catch (Clasnostfundai Express E) {// To-O Auto-Generated Catch Block e.printStackTrace (); }} Public static zero main (string [] args) {long l = System.currentTimeMillis (); Connection Conn = Null; {For (ii = 0; i & lt; 100; i ++) {conn = DriverManager.getConnection ("jdbc: mysql: // localhost: 3306 / jdbcdemo", "root", "sph815 @ cs") try; Conn.close (); }} Catch (eclipse e) {// Tudo auto-generated cal block e.printstaxtress (); } System.out.println (System.currentTimeMillis () - l); }}

But when I test it using my run time, then I do not understand why more time in the job?

  public class testDBCP {static {try {class.forName ("com.mysql.jdbc.Driver"); } Catch (Clasnostfundai Express E) {// To-O Auto-Generated Catch Block e.printStackTrace (); }} Public static zero main (string [] args) {long l = System.currentTimeMillis (); {For int i = 0; I & lt; 100; I ++} {Try DriverManager.getConnection ("jdbc: mysql: // localhost: 3306 / jdbcdemo", "root", "sph815 @ cs"); }} Catch (eclipse e) {// Tudo auto-generated cal block e.printstaxtress (); } System.out.println (System.currentTimeMillis () - l); }}  

You are assuming that execute an additional statement (which is the connection to Closes) means that the program will take longer because execution of close () statements adds additional CPU usage.

If you do not execute it, you can save this CPU time, although the database is handled more, which can degrade its performance, so to run the getConnection () statement It will take more time to execute as the number of open connections.

This is probably the reason why your second version performs at a slow pace from the beginning.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -