|
14 | 14 |
|
15 | 15 | import java.math.BigDecimal; |
16 | 16 | import java.math.BigInteger; |
17 | | -import java.sql.*; |
| 17 | +import java.sql.Connection; |
| 18 | +import java.sql.PreparedStatement; |
| 19 | +import java.sql.ResultSet; |
| 20 | +import java.sql.ResultSetMetaData; |
| 21 | +import java.sql.SQLException; |
| 22 | +import java.sql.Types; |
18 | 23 | import java.time.LocalDateTime; |
19 | 24 | import java.time.OffsetDateTime; |
20 | 25 | import java.time.OffsetTime; |
21 | 26 | import java.time.ZoneId; |
22 | | -import java.util.*; |
| 27 | +import java.util.Collections; |
| 28 | +import java.util.Iterator; |
| 29 | +import java.util.LinkedHashMap; |
| 30 | +import java.util.List; |
| 31 | +import java.util.Map; |
| 32 | +import java.util.Spliterator; |
| 33 | +import java.util.Spliterators; |
| 34 | +import java.util.UUID; |
23 | 35 | import java.util.stream.Stream; |
24 | 36 | import java.util.stream.StreamSupport; |
25 | 37 |
|
26 | | -import static apoc.load.util.JdbcUtil.*; |
| 38 | +import static apoc.load.util.JdbcUtil.getConnection; |
| 39 | +import static apoc.load.util.JdbcUtil.getSqlOrKey; |
| 40 | +import static apoc.load.util.JdbcUtil.getUrlOrKey; |
| 41 | +import static apoc.load.util.JdbcUtil.obfuscateJdbcUrl; |
27 | 42 |
|
28 | 43 | /** |
29 | 44 | * @author mh |
@@ -96,10 +111,7 @@ private Stream<RowResult> executeQuery(String urlOrKey, String tableOrSelect, Ma |
96 | 111 | throw sqle; |
97 | 112 | } |
98 | 113 | } catch (Exception e) { |
99 | | - log.error(String.format("Cannot execute SQL statement `%s`.%nError:%n%s", query, e.getMessage()),e); |
100 | | - String errorMessage = "Cannot execute SQL statement `%s`.%nError:%n%s"; |
101 | | - if(e.getMessage().contains("No suitable driver")) errorMessage="Cannot execute SQL statement `%s`.%nError:%n%s%n%s"; |
102 | | - throw new RuntimeException(String.format(errorMessage, query, e.getMessage(), "Please download and copy the JDBC driver into $NEO4J_HOME/plugins,more details at https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_load_jdbc_resources"), e); |
| 114 | + throw logsErrorAndThrowsException(e, query, log); |
103 | 115 | } |
104 | 116 | } |
105 | 117 |
|
@@ -134,13 +146,24 @@ private Stream<RowResult> executeUpdate(String urlOrKey, String query, Map<Strin |
134 | 146 | throw sqle; |
135 | 147 | } |
136 | 148 | } catch (Exception e) { |
137 | | - log.error(String.format("Cannot execute SQL statement `%s`.%nError:%n%s", query, e.getMessage()),e); |
138 | | - String errorMessage = "Cannot execute SQL statement `%s`.%nError:%n%s"; |
139 | | - if(e.getMessage().contains("No suitable driver")) errorMessage="Cannot execute SQL statement `%s`.%nError:%n%s%n%s"; |
140 | | - throw new RuntimeException(String.format(errorMessage, query, e.getMessage(), "Please download and copy the JDBC driver into $NEO4J_HOME/plugins,more details at https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_load_jdbc_resources"), e); |
| 149 | + throw logsErrorAndThrowsException(e, query, log); |
141 | 150 | } |
142 | 151 | } |
143 | 152 |
|
| 153 | + private static RuntimeException logsErrorAndThrowsException(Exception e, String query, Log log) { |
| 154 | + String errorMessage = "Cannot execute SQL statement `%s`.%nError:%n%s"; |
| 155 | + String exceptionMsg = e.getMessage(); |
| 156 | + |
| 157 | + if(e.getMessage().contains("No suitable driver")) { |
| 158 | + errorMessage = "Cannot execute SQL statement `%s`.%nError:%n%s%n%s"; |
| 159 | + exceptionMsg = obfuscateJdbcUrl(e.getMessage()); |
| 160 | + } |
| 161 | + |
| 162 | + Exception ex = new Exception(exceptionMsg); |
| 163 | + log.error(String.format("Cannot execute SQL statement `%s`.%nError:%n%s", query, exceptionMsg), ex); |
| 164 | + return new RuntimeException(String.format(errorMessage, query, exceptionMsg, "Please download and copy the JDBC driver into $NEO4J_HOME/plugins, more details at https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_load_jdbc_resources"), ex); |
| 165 | + } |
| 166 | + |
144 | 167 | static void closeIt(Log log, AutoCloseable...closeables) { |
145 | 168 | for (AutoCloseable c : closeables) { |
146 | 169 | try { |
|
0 commit comments