Questions Tagged With databasehttps://answers.axonivy.com/tags/database/?type=rss&user=wesingquestions tagged <span class="tag">database</span>enMon, 23 Jul 2018 23:32:38 -0400How to access database in a faces Validatorhttps://answers.axonivy.com/questions/3364/how-to-access-database-in-a-faces-validator<p>Hi all, I am new to AXON IVY. Hope you can be patient with me.</p> <p>I am trying to use that code here: <a href="https://answers.axonivy.com/questions/314/using-db-connection-from-pis">https://answers.axonivy.com/questions/314/using-db-connection-from-pis</a> (provided by Ivy Support Team) in a Java class in a CustomValidator class to look up a database table. Somehow I could not resolve the Ivy object. </p> <p>I tried looking up getProcessEngineHook method in <a href="https://developer.axonivy.com/doc/latest/PublicAPI">https://developer.axonivy.com/doc/latest/PublicAPI</a> but the search doesn't return any results.</p> <p>My codes as follows:</p> <pre><code>package trial.facesValidation; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.Validator; import javax.faces.validator.ValidatorException; import java.sql.Connection; // To validate if Item Name already existed in Parts table in Database @FacesValidator("trial.facesValidation.CustomItemValidator") public class CustomItemValidator implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { //connect to the database Connection dbconnection = ivy.getProcessEngineHook().getDbConnection("TrialDBConn"); try { // execute some sql queries } finally { // close the connection dbconnection.close(); } </code></pre>wesingMon, 23 Jul 2018 23:32:38 -0400https://answers.axonivy.com/questions/3364/how-to-access-database-in-a-faces-validatorjsfdatabase