Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
import org.joget.apps.form.model.*;
import org.joget.apps.form.service.*;
import java.sql.*;
import java.util.*;
import javax.sql.DataSource;
import org.joget.apps.app.service.AppUtil;
import java.sql.PreparedStatement;


FormRowSet f = new FormRowSet();
f.setMultiRow(true);

//Get Joget's current datasource configs
DataSource ds = (DataSource) AppUtil.getApplicationContext().getBean("setupDataSource");

con = ds.getConnection();

if (!con.isClosed()) {
	//Get the URL parameter
	String recordId = "#requestParam.id#";
 
	//Here you can query from one or multiple tables using JOIN etc
	String sql = "SELECT * FROM your_table_name WHERE id=?";
	PreparedStatement stmt = con.prepareStatement(sql);
	stmt.setString(1, recordId);
 
	//Execute the SELECT SQL statement
	ResultSet rs = stmt.executeQuery();
		
	//Get value from columns of record(s)
	while (rs.next()) {
		FormRow r1 = new FormRow();
		r1.put("gridColumn1", rs.getString(1));
		r1.put("gridColumn2", rs.getString(2));
		r1.put("gridColumn3", rs.getString(3));
		f.add(r1);
	}
}

return f;

...