sexta-feira, 24 de janeiro de 2014

Using HASH VARIABLE - JOGET - BEAN SHELL FORM BINDER

This programming code has the purpose of populate a selectbox.


// Lit all user
import java.sql.*;
import java.util.*;
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;

public FormRowSet test() {
FormRowSet f = new FormRowSet();
f.setMultiRow(true);

Connection con = null;

Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3307/jwdb?useUnicode=true&characterEncoding=UTF-8", "root", ""); // declare datasource

if(!con.isClosed())
{

String pId = "#currentUser.username#";
PreparedStatement stmt = con.prepareStatement("select id, CONCAT(CONCAT(firstName, ' '), lastName) from dir_user WHERE username=? order by firstname asc"); //  SQL query
stmt.setString(1, pId);

ResultSet rs = stmt.executeQuery();
while (rs.next()) {
            FormRow r1 = new FormRow();
            r1.put(FormUtil.PROPERTY_VALUE, rs.getString(1));
            r1.put(FormUtil.PROPERTY_LABEL, rs.getString(2));
            f.add(r1);
        }
}

return f;
}
return test();

Nenhum comentário:

Postar um comentário