equal
deleted
inserted
replaced
24 import java.sql.Connection; |
24 import java.sql.Connection; |
25 import java.sql.DriverManager; |
25 import java.sql.DriverManager; |
26 import java.sql.PreparedStatement; |
26 import java.sql.PreparedStatement; |
27 import java.sql.ResultSet; |
27 import java.sql.ResultSet; |
28 import java.sql.SQLException; |
28 import java.sql.SQLException; |
|
29 import java.util.logging.Level; |
|
30 import java.util.logging.Logger; |
29 |
31 |
30 /** |
32 /** |
31 * |
33 * |
32 * @author Ing. František Kučera (frantovo.cz) |
34 * @author Ing. František Kučera (frantovo.cz) |
33 */ |
35 */ |
34 public class DatabaseConnection implements AutoCloseable { |
36 public class DatabaseConnection implements AutoCloseable { |
35 |
37 |
|
38 private static final Logger log = Logger.getLogger(DatabaseConnection.class.getName()); |
36 private DatabaseDefinition databaseDefinition; |
39 private DatabaseDefinition databaseDefinition; |
37 private Connection connection; |
40 private Connection connection; |
38 |
41 |
39 public DatabaseConnection(DatabaseDefinition databaseDefinition) throws SQLException { |
42 public DatabaseConnection(DatabaseDefinition databaseDefinition) throws SQLException { |
40 this.databaseDefinition = databaseDefinition; |
43 this.databaseDefinition = databaseDefinition; |
56 formatter.writeEndDatabase(); |
59 formatter.writeEndDatabase(); |
57 } |
60 } |
58 |
61 |
59 private void processCommand(SQLCommand sqlCommand, Formatter formatter) throws SQLException { |
62 private void processCommand(SQLCommand sqlCommand, Formatter formatter) throws SQLException { |
60 try (PreparedStatement ps = sqlCommand.prepareStatement(connection)) { |
63 try (PreparedStatement ps = sqlCommand.prepareStatement(connection)) { |
|
64 log.log(Level.FINE, "Statement prepared"); |
61 sqlCommand.parametrize(ps); |
65 sqlCommand.parametrize(ps); |
62 |
66 |
63 boolean isRS = ps.execute(); |
67 boolean isRS = ps.execute(); |
|
68 log.log(Level.FINE, "Statement executed"); |
64 if (isRS) { |
69 if (isRS) { |
65 try (ResultSet rs = ps.getResultSet()) { |
70 try (ResultSet rs = ps.getResultSet()) { |
66 processResultSet(sqlCommand, rs, formatter); |
71 processResultSet(sqlCommand, rs, formatter); |
67 } |
72 } |
68 } else { |
73 } else { |