I'm trying to create a LocalDataSource with the intellij plugin sdk. But i can't figure out how to set the password of a DataSource.
Example:
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);
CodePudding user response:
This should work,
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);
}
It seems also you can do it as part of the constructor,
LocalDataSource ds = new LocalDataSource("Test Data Source", "oracle.jdbc.OracleDriver",
jdbcUrl, "database_user", "sekret");