To use the functionality of DHTMLX Connector, first you should initialize it.
Generally, both client- and server-sides are concerned in it.
Specify connector file in the load method of a component.
//index.html myGrid = new dhtmlXGridObject("someContainer");// initializes grid ... myGrid.load("myconnector.do");
1) Specify connector file in the load method of a component;
2) Initialize dhtmlxDataProcessor on the client side (read more about it here).
//index.html myGrid = new dhtmlXGridObject("someContainer");// initializes grid ... myGrid.load("myconnector.do"); myDP = new dataProcessor("myconnector.do");// initializes dhtmlxDataProcessor myDP.init(myGrid);
Samples client-side initialization
import java.sql.Connection; import java.sql.DriverManager; import com.dhtmlx.connector.*; /** * The Class BasicConnector. */ public class BasicConnector extends ConnectorServlet { @Override protected void configure() { //obtain DB connection Connection conn=null; try { Class.forName ("com.mysql.jdbc.Driver").newInstance (); conn = DriverManager.getConnection("jdbc:mysql://localhost/sampleDB","root",""); } catch (Throwable e) { e.printStackTrace(); } //Initializes connector GridConnector c = new GridConnector(conn); //configures the used table and fields c.render_table("grid50000", "item_id", "item_nm,item_cd"); } }
Samples server-side initialization
The code above has been used starting from the initial version, but it has one disadvantage - it is not thread safe. Starting from the version 1.0 you can create a thread safe connector. Its init code will look as:
public class BasicConnector extends ThreadSafeConnectorServlet{ @Override protected void configure(HttpServletRequest req, HttpServletResponse res) { //obtain DB connection Connection conn=null; try { Class.forName ("com.mysql.jdbc.Driver").newInstance (); conn = DriverManager.getConnection("jdbc:mysql://localhost/sampleDB","root",""); } catch (Throwable e) { e.printStackTrace(); } //Initialize connector GridConnector c = new GridConnector(conn); c.servlet(req, res); //configure used table and fields c.render_table("grid50000", "item_id", "item_nm,item_cd"); } }
There are two main differences: