summaryrefslogtreecommitdiff
path: root/qadevOOo/runner/util
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-10-13 13:20:47 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-10-14 07:15:41 +0000
commita2c481457cd2d03263054a5fefe80da316e09a44 (patch)
tree5b8717ae1fdfd55b5c3c56410408acd92a94ef42 /qadevOOo/runner/util
parentfa6ac05beaaf1160c205e40099b99f0ed0efb131 (diff)
runner: finally block to ensure that a resource is closed (Prior to Java SE 7)
http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html Change-Id: I5ecefd3e5bf84fea2a8735a44236ed4c86b440c4 Reviewed-on: https://gerrit.libreoffice.org/11950 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'qadevOOo/runner/util')
-rw-r--r--qadevOOo/runner/util/DBTools.java32
1 files changed, 21 insertions, 11 deletions
diff --git a/qadevOOo/runner/util/DBTools.java b/qadevOOo/runner/util/DBTools.java
index 7960a8dac488..f6e7c815bc81 100644
--- a/qadevOOo/runner/util/DBTools.java
+++ b/qadevOOo/runner/util/DBTools.java
@@ -326,6 +326,7 @@ public class DBTools {
public void initTestTableUsingJDBC(String tbl_name, DataSourceInfo dsi)
throws java.sql.SQLException,
ClassNotFoundException {
+
//register jdbc driver
if ( dsi.Info[0].Name.equals("JavaDriverClass") ) {
Class.forName((String)dsi.Info[0].Value);
@@ -333,21 +334,30 @@ public class DBTools {
Class.forName(TST_JDBC_DRIVER);
}
- //getting connection
Connection connection = null;
+ Statement statement = null;
+ try {
+ //getting connection
+ connection = DriverManager.getConnection(dsi.URL, dsi.User, dsi.Password);
+ try {
+ statement = connection.createStatement();
- connection = DriverManager.getConnection(
- dsi.URL, dsi.User, dsi.Password);
- Statement statement = connection.createStatement();
-
- //drop table
- dropMySQLTable(statement, tbl_name);
+ //drop table
+ dropMySQLTable(statement, tbl_name);
- //create table
- createMySQLTable(statement, tbl_name);
+ //create table
+ createMySQLTable(statement, tbl_name);
- //insert some content
- insertContentMySQLTable(statement, tbl_name);
+ //insert some content
+ insertContentMySQLTable(statement, tbl_name);
+ } finally {
+ if (statement != null)
+ statement.close();
+ }
+ } finally {
+ if (connection != null)
+ connection.close();
+ }
}
/**