1
0
-1

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();

 

    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

      I found it this is correct

      r1.put(FormUtil.PROPERTY_VALUE, rs.getString(1));

      r1.put(FormUtil.PROPERTY_LABEL, rs.getString(1));

        CommentAdd your comment...
      1.  
        1
        0
        -1
        • type of con is not defined. It should be 

          Connection con = DriverManager.getConnection("jdbc:sqlserver://host:1433;DatabaseName=databasename;useUnicode=true;characterEncoding=UTF-8", "database user", "database password");
        • You're returning the result before closing the connection.

             con.close();
             return f;
          CommentAdd your comment...
        1.  
          0
          -1
          -2

          Thank you for your help but it didn't change anything.

            CommentAdd your comment...