AnsweredAssumed Answered

Connect External Databse

Question asked by sanjaybandhniya on Aug 15, 2018
Latest reply on Aug 17, 2018 by sanjaybandhniya

I am trying to connect external database from alfresco to get constraint like below way.

 

<bean id="DataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="${jdbcDriver}" />
      <property name="url" value="${jdbcUrl}" />
      <property name="username" value="${jdbcUserName}" />
      <property name="password" value="${jdbcPassword}" />
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
   <constructor-arg ref="DataSource" />
</bean>

<bean id="documentDAOImpl" class="com.dao.DocumentDAOImpl">
   <property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>

<bean id="batchTypeConstraints" class="com.constraints.BatchTypeConstraints">
      <property name="documentDAOImpl" ref="documentDAOImpl" />
</bean>

 

 

 

public class BatchTypeConstraints extends ListOfValuesConstraint implements Serializable {

 

   private DocumentDAOImpl documentDAOImpl;

   public DocumentDAOImpl getDocumentDAOImpl() {
   return documentDAOImpl;
}

public void setDocumentDAOImpl(DocumentDAOImpl documentDAOImpl) {
      this.documentDAOImpl = documentDAOImpl;
}

@Override
public void setAllowedValues(List allowedValues) {
}

@Override
public void setCaseSensitive(boolean caseSensitive) {
}

public void initialize() {
super.setCaseSensitive(false);
this.getDataFromDb();
}

protected void getDataFromDb() {
try {
      List<MetaDataModel> pShortNames = documentDAOImpl.getAllBatchByWorkFlowType();
      List<String> allowedValue = new ArrayList<String>();
for (MetaDataModel pShortName : pShortNames) {
   allowedValue.add(pShortName.getName());
}
super.setAllowedValues(allowedValue);
} catch (Exception e) {
e.printStackTrace();
}

}
}

 

It's giving me null pointer error at this line :

List<MetaDataModel> pShortNames = documentDAOImpl.getAllBatchByWorkFlowType();

I think data base is not connecting.

How Can i connect ?

Outcomes