Problem with Bean Shell Form Binder and MS SQL

Confluence User - 18 Feb, 2016

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

 

forms;beanshell;mssql

3


19 Feb, 2016
confluenceUser
confluenceUser
  • 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;
22 Feb, 2016
confluenceUser
confluenceUser

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

23 Feb, 2016
confluenceUser
confluenceUser

I found it this is correct

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

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

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print