use of org.talend.components.jdbc.runtime.setting.AllSetting in project components by Talend.
the class JDBCRowSourceOrSink method validate.
@Override
public ValidationResult validate(RuntimeContainer runtime) {
if (runtime != null) {
runtime.setComponentData(runtime.getCurrentComponentId(), CommonUtils.getStudioNameFromProperty(ComponentConstants.RETURN_QUERY), setting.getSql());
}
ValidationResultMutable vr = new ValidationResultMutable();
AllSetting setting = properties.getRuntimeSetting();
String sql = setting.getSql();
boolean usePreparedStatement = setting.getUsePreparedStatement();
boolean dieOnError = setting.getDieOnError();
Connection conn = null;
try {
conn = connect(runtime);
} catch (ClassNotFoundException | SQLException e) {
throw CommonUtils.newComponentException(e);
}
try {
if (usePreparedStatement) {
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
JdbcRuntimeUtils.setPreparedStatement(pstmt, setting.getIndexs(), setting.getTypes(), setting.getValues());
pstmt.execute();
}
} else {
try (Statement stmt = conn.createStatement()) {
stmt.execute(sql);
}
}
if (useCommit) {
conn.commit();
}
} catch (Exception ex) {
if (dieOnError) {
vr.setStatus(Result.ERROR);
vr.setMessage(CommonUtils.correctExceptionInfo(ex));
} else {
System.err.println(CommonUtils.correctExceptionInfo(ex));
}
} finally {
if (!useExistedConnection) {
try {
conn.close();
} catch (SQLException e) {
throw CommonUtils.newComponentException(e);
}
}
}
return vr;
}
Aggregations