How to retrieve a field or a column in a database into a form

Confluence User - 17 Jan, 2017

How to retrieve a field or a column in a database into a form using userview key or any method or way

userviews;datalists

4


17 Jan, 2017
confluenceUser
confluenceUser

Hi,

I believe you want to display a field in your form by retrieving it's value from your database records. Don't you?

If the database values in question aren't created by Joget, you can try creating a Form Load Binder Beanshell with your JDBC logic to get the database values in your form.

Hope this helps!

Thanks 

17 Jan, 2017
confluenceUser
confluenceUser

It is also possible to query through jdbc from the properties of a specific section of a form (Edit Section > Data Binder > Configure Bean Shell Form Binder), and if you are sure that the query returns a single value, take it directly to a form element (a hidden field or text box), with something like (sql is a string with the query):

ApplicationContext ac = AppUtil.getApplicationContext();
 DataSource ds = (DataSource) ac.getBean("setupDataSource");
 conn = ds.getConnection();
Statement stmt = conn.createStatement();
 ResultSet rset = stmt.executeQuery(sql);
String query_result_variable = "";
 if (rset.next())
 {
query_result_variable = rset.getString(1);
 }

 

and after this process, write the result to the form element:
FormRow r = new FormRow(); 
r.put("form_field", query_result_variable);
f.add(r);



17 Jan, 2017
confluenceUser
confluenceUser

Good answer. Just that you must remember to close your resources (especially database connection) in a try-finally block, otherwise you might exhaust your connections http://stackoverflow.com/questions/2225221/closing-database-connections-in-java/2225275#2225275

17 Jan, 2017
confluenceUser
confluenceUser

Thanks and agree! Of course, I did not put the whole code. Another additional thing is, as mentioned in the forums, not add all the java libraries, just the necessary ones.

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print