如何在 LocalDataSource 中设置密码
How to set password in LocalDataSource
我正在尝试使用 intellij 插件 sdk 创建 LocalDataSource。但是我不知道如何设置数据源的密码。
示例:
String uniqueName = DbUtil.generateUniqueDataSourceName(project, "Test");
LocalDataSource dataSource = LocalDataSource.create(uniqueName, "com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/test", uniqueName);
dataSource.setUsername("testuser");
dataSource.setPasswordStorage(LocalDataSource.Storage.PERSIST);
LocalDataSourceManager.getInstance(project).addDataSource(dataSource);
这应该可以,
private void addPasswordToLocalDataSource(@NotNull LocalDataSource ds, @Nullable String password) {
ds.setPasswordStorage(LocalDataSource.Storage.PERSIST);
DatabaseCredentials.getInstance().setPassword(ds, password == null ? null : new OneTimeString(password));
ds.resolveDriver();
ds.ensureDriverConfigured();
DataSourceStorage.getProjectStorage(myProject).addDataSource(ds);
}
看来你也可以把它作为构造函数的一部分,
LocalDataSource ds = new LocalDataSource("Test Data Source", "oracle.jdbc.OracleDriver",
jdbcUrl, "database_user", "sekret");
我正在尝试使用 intellij 插件 sdk 创建 LocalDataSource。但是我不知道如何设置数据源的密码。
示例:
String uniqueName = DbUtil.generateUniqueDataSourceName(project, "Test");
LocalDataSource dataSource = LocalDataSource.create(uniqueName, "com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/test", uniqueName);
dataSource.setUsername("testuser");
dataSource.setPasswordStorage(LocalDataSource.Storage.PERSIST);
LocalDataSourceManager.getInstance(project).addDataSource(dataSource);
这应该可以,
private void addPasswordToLocalDataSource(@NotNull LocalDataSource ds, @Nullable String password) {
ds.setPasswordStorage(LocalDataSource.Storage.PERSIST);
DatabaseCredentials.getInstance().setPassword(ds, password == null ? null : new OneTimeString(password));
ds.resolveDriver();
ds.ensureDriverConfigured();
DataSourceStorage.getProjectStorage(myProject).addDataSource(ds);
}
看来你也可以把它作为构造函数的一部分,
LocalDataSource ds = new LocalDataSource("Test Data Source", "oracle.jdbc.OracleDriver",
jdbcUrl, "database_user", "sekret");