Skip to content

Commit e2b9ecb

Browse files
author
banzhe
committed
feat: update druid datasouece when select datasource
1 parent 92aa933 commit e2b9ecb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/main/java/io/github/linyimin/plugin/sql/DatasourceComponent.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@ public Connection getConnection() throws Exception {
2626
}
2727

2828
public void updateDatasource() {
29+
this.close();
2930
try {
30-
if (dataSource != null && !dataSource.isClosed()) {
31+
dataSource = createDatasource();
32+
} catch (Exception ignored) {
33+
if (dataSource != null) {
34+
dataSource.close();
35+
}
36+
}
37+
}
38+
39+
public void close() {
40+
try {
41+
if (dataSource != null) {
3142
dataSource.close();
3243
}
33-
dataSource = createDatasource();
3444
} catch (Exception ignored) {
35-
if (dataSource != null && !dataSource.isClosed()) {
45+
if (dataSource != null) {
3646
dataSource.close();
3747
}
3848
}

src/main/java/io/github/linyimin/plugin/ui/DatasourceDialog.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ private void initDatasource() {
141141
password.setText(component.getPassword());
142142
database.setText(component.getDatabase());
143143

144+
DatasourceComponent datasourceComponent = project.getService(DatasourceComponent.class);
145+
datasourceComponent.updateDatasource();
146+
144147
});
145148

146149
}

0 commit comments

Comments
 (0)