Problem with Bean Shell Form Binder and MS SQL
I try to load name and surname to a select box, from an external MS SQL server and then retrieve the mail of that selected user. I get no error but the list shows only blank entries.
I've used JDBC Datalist Database Binder and works fine. Do you have any idea how can I do this?
I really appreciate any help you can provide.
This is my code:
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import org.apache.commons.collections.SequencedHashMap;
import java.util.*;
public FormRowSet test() {
FormRowSet f = new FormRowSet();
f.setMultiRow(true);
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
con = DriverManager.getConnection("jdbc:sqlserver://host:1433;DatabaseName=databasename;useUnicode=true;characterEncoding=UTF-8", "database user", "database password");
if(!con.isClosed()){
String sql = "SELECT surname FROM Table";
PreparedStatement stmt = con.prepareStatement(sql);
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(1));
f.add(r1);
}
}
return f;
con.close();
}
return test();