1313public class Connection implements AutoCloseable {
1414
1515
16- private java .sql .Connection Conn = null ;
17- private long Speed ;
16+ private java .sql .Connection conn = null ;
1817 private Database database ;
18+ private long t ;
1919
2020
2121 //**************************************************************************
@@ -49,7 +49,7 @@ public boolean isOpen(){
4949 */
5050 public boolean isClosed (){
5151 try {
52- return Conn .isClosed ();
52+ return conn .isClosed ();
5353 }
5454 catch (Exception e ){
5555 return true ;
@@ -64,7 +64,7 @@ public boolean isClosed(){
6464 * (in milliseconds)
6565 */
6666 public long getConnectionSpeed (){
67- return Speed ;
67+ return t ;
6868 }
6969
7070
@@ -74,7 +74,7 @@ public long getConnectionSpeed(){
7474 /** Used to retrieve the java.sql.Connection for this Connection
7575 */
7676 public java .sql .Connection getConnection (){
77- return Conn ;
77+ return conn ;
7878 }
7979
8080
@@ -130,17 +130,17 @@ public boolean open(Database database) throws SQLException {
130130 }
131131
132132
133- Conn = Driver .connect (url , properties );
133+ conn = Driver .connect (url , properties );
134134 }
135135 else {
136- Conn = connectionPool .getConnection ().getConnection ();
136+ conn = connectionPool .getConnection ().getConnection ();
137137 }
138138
139139
140- boolean isClosed = Conn .isClosed ();
140+ boolean isClosed = conn .isClosed ();
141141
142142
143- Speed = System .currentTimeMillis ()-startTime ;
143+ t = System .currentTimeMillis ()-startTime ;
144144 return !isClosed ;
145145 }
146146
@@ -172,16 +172,16 @@ public boolean open(java.sql.Connection conn){
172172 boolean isClosed ;
173173 try {
174174 if (database ==null ) database = new Database (conn );
175- Conn = conn ;
176- isClosed = Conn .isClosed ();
175+ this . conn = conn ;
176+ isClosed = conn .isClosed ();
177177 }
178178 catch (Exception e ){
179179 //System.out.println("Failed");
180180 //System.out.println(database.getDriver().getVendor() + " ERROR: " + e.toString());
181181 isClosed = true ;
182182 }
183183
184- Speed = 0 ;
184+ t = 0 ;
185185 return !isClosed ;
186186 }
187187
@@ -206,9 +206,11 @@ public boolean open(java.sql.Connection conn){
206206 */
207207 public void close (){
208208 //System.out.println("Closing connection...");
209- try {Conn .close ();}
210- catch (Exception e ){
209+ if (isOpen ()) {
210+ try {conn .close ();}
211+ catch (Exception e ){
211212 //e.printStackTrace();
213+ }
212214 }
213215 }
214216
@@ -372,9 +374,9 @@ public Recordset getRecordset(String sql) throws SQLException {
372374 /** Used to execute a prepared sql statement (e.g. "delete from my_table").
373375 */
374376 public void execute (String sql ) throws SQLException {
375- try (java .sql .PreparedStatement stmt = Conn .prepareStatement (sql )){
377+ try (java .sql .PreparedStatement stmt = conn .prepareStatement (sql )){
376378 stmt .execute ();
377- try { Conn .commit (); } catch (Exception e ){}
379+ try { conn .commit (); } catch (Exception e ){}
378380 }
379381 }
380382
0 commit comments