Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void executeStatement(SQLExecutePlan plan, Statement statement, SQLQuery
fs.add(HexUtils.bytesToHex((byte[]) obj));
} else if (obj instanceof Blob) {
fs.add(HexUtils.bytesToHex(((Blob) obj).getBytes(1, (int) ((Blob) obj).length())));
} else if (obj.getClass().getSimpleName().equalsIgnoreCase("pgobject")) {
} else if (obj!= null && obj.getClass().getSimpleName().equalsIgnoreCase("pgobject")) {
fs.add(obj.toString());
} else {
fs.add(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import org.jumpserver.chen.framework.datasource.sql.SQL;
import org.jumpserver.chen.modules.base.ssl.JKSGenerator;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Properties;

public class MysqlConnectionManager extends BaseConnectionManager {
Expand All @@ -33,6 +38,34 @@ public void ping() throws SQLException {
}


@Override
public Connection getConnection() throws SQLException {
var conn = super.getConnection();
setTimeZone(conn);
return conn;
}

@Override
public Connection getPhysicalConnection() throws SQLException {
var conn = super.getPhysicalConnection();
setTimeZone(conn);
return conn;
}

private void setTimeZone(Connection conn) throws SQLException {
ZoneId zoneId = ZoneId.systemDefault();

ZonedDateTime now = ZonedDateTime.now(zoneId);
ZoneOffset offset = now.getOffset();

String offsetStr = offset.toString();

try (Statement stmt = conn.createStatement()) {
stmt.execute("SET time_zone = '" + offsetStr + "'");
}
}


protected void setSSLProps(Properties props) {
if (this.getConnectInfo().getOptions().get("useSSL") != null
&& (boolean) this.getConnectInfo().getOptions().get("useSSL")) {
Expand Down