zhangshenghang commented on code in PR #10048:
URL: https://github.com/apache/seatunnel/pull/10048#discussion_r2538242252


##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/psql/PostgresJdbcRowConverter.java:
##########
@@ -69,6 +73,47 @@ public String converterName() {
         return DatabaseIdentifier.POSTGRESQL;
     }
 
+    @Override
+    protected void setValueToStatementByDataType(
+            Object value,
+            PreparedStatement statement,
+            SeaTunnelDataType<?> seaTunnelDataType,
+            int statementIndex,
+            @Nullable String sourceType)
+            throws SQLException {
+        if (seaTunnelDataType.getSqlType().equals(SqlType.TIMESTAMP_TZ)) {
+            if (value == null) {
+                statement.setNull(statementIndex, 
java.sql.Types.TIMESTAMP_WITH_TIMEZONE);
+                return;
+            }
+            OffsetDateTime offsetDateTime = (OffsetDateTime) value;
+            try {
+                statement.setObject(statementIndex, offsetDateTime);
+                return;
+            } catch (AbstractMethodError | SQLException e) {
+                try {
+                    PGobject timestampTzObject = new PGobject();
+                    timestampTzObject.setType("timestamptz");
+                    timestampTzObject.setValue(offsetDateTime.toString());
+                    statement.setObject(statementIndex, timestampTzObject);
+                    return;
+                } catch (SQLException pge) {
+                    try {
+                        statement.setTimestamp(
+                                statementIndex, 
Timestamp.from(offsetDateTime.toInstant()));
+                        return;
+                    } catch (SQLException se) {
+                        throw new SQLException(
+                                "Failed to set TIMESTAMP_TZ value for 
PostgreSQL using all methods",
+                                se);
+                    }
+                }
+            }
+        }

Review Comment:
   Three layers of try-catch is a very bad writing style, can it be handled 
before an exception occurs?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to