|
|
|
|
Re: Any Doc. to Connect to MySQL [message #1747290 is a reply to message #1747263] |
Fri, 11 November 2016 12:33  |
Eclipse User |
|
|
|
When you provide examples, it is always a tradeoff between being simple and being complex. Of course, in normal cases, you do not want to have the connection path, username and password hardcoded in your application code. I recommend to use the configuration possibilities offered by scout.
With this class to define the properties:
package com.example.helloworld.server.sql;
import org.eclipse.scout.rt.platform.config.AbstractStringConfigProperty;
public class DatabaseProperties {
public static class JdbcMappingNameProperty extends AbstractStringConfigProperty {
@Override
protected String getDefaultValue() {
return "jdbc:mysql://localhost:3306/testdb";
}
@Override
public String getKey() {
return "myapp.database.jdbc.mapping.name";
}
}
public static class UsernameProperty extends AbstractStringConfigProperty {
@Override
protected String getDefaultValue() {
return "root";
}
@Override
public String getKey() {
return "myapp.database.username";
}
}
public static class PasswordProperty extends AbstractStringConfigProperty {
@Override
protected String getDefaultValue() {
return "";
}
@Override
public String getKey() {
return "myapp.database.password";
}
}
}
Your service will looks like that:
package com.example.helloworld.server.sql;
import org.eclipse.scout.rt.platform.config.CONFIG;
import org.eclipse.scout.rt.server.jdbc.mysql.AbstractMySqlSqlService;
public class HelloworldSqlService extends AbstractMySqlSqlService {
@Override
protected String getConfiguredJdbcMappingName() {
return CONFIG.getPropertyValue(JdbcMappingNameProperty.class);
}
@Override
protected String getConfiguredUsername() {
return CONFIG.getPropertyValue(UsernameProperty.class);
}
@Override
protected String getConfiguredPassword() {
return CONFIG.getPropertyValue(PasswordProperty.class);
}
}
The values will be read from:
* system properties
* an entry in a config.properties file
* environment variables
(see the documentation if you need more details).
This way you can set different values for your different environement (INTEGRATION, PRODUCTION, ...)
|
|
|
Powered by
FUDForum. Page generated in 0.03198 seconds