Hi,
I want to use a java.sql.ResultSet as datasource to my webgrid. I see that there is a ResultSetDataModel provided for use. I tried creating one using the result set I have but did not get any success.
Can anyone please provide me a sample code to use the resultset as a data source. Thanks in advance.
Hello Leo....
I am trying to copy the sample code for you but I am not able to see the updates..retrying in parts...DAO.java----------------------------------
package MyPackage.Test;
import javax.faces.model.ResultSetDataModel;import java.sql.*;
public class DAO { private static ResultSetDataModel rs = null; private static Connection conn= null; private static ResultSet result =null;
public static ResultSetDataModel getEmployees() { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("Creating Connection"); conn = DriverManager.getConnection("jdbc:odbc:MyTable"); if(conn!=null) { Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); System.out.println("Using ResultSet"); result = stmt.executeQuery("select * from Table1"); rs = new ResultSetDataModel(result); System.out.println("Accessing Data"); } else { System.out.println("Error"); } } catch(Exception e){ e.printStackTrace(); } return rs; }}
DataTest.java------------------------------------
import javax.faces.model.ResultSetDataModel;
public class DataTest {
protected ResultSetDataModel rs =null;
public ResultSetDataModel getEmployees() {
rs= DAO.getEmployees(); return rs; }
}
index.jsp----------------------------------..<f:view> <h:form> <h:panelGroup styleClass="main"> <%-- TITLE --%> <h:outputText styleClass="title" value="WebGrid Sample" /> <h:panelGroup styleClass="section">
<ig:gridView dataSource="#{Test.employees}" pageSize="10"> <f:facet name="header"> <h:outputText value="Employee List" /> </f:facet> <ig:column> <f:facet name="header"> <h:outputText value="First Name" /> </f:facet> <h:outputText value="#{DATA_ROW.Name}" /> </ig:column> <ig:column> <f:facet name="header"> <h:outputText value="Phone Number" /> </f:facet> <h:outputText value="#{DATA_ROW.Phone}" /> </ig:column></ig:gridView>
</h:panelGroup> </h:panelGroup> </h:form></f:view>....
faces-config.xml---------------------------------<faces-config><managed-bean> <managed-bean-name>Test</managed-bean-name> <managed-bean-class>MyPackage.Test.DataTest</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean>
</faces-config>
faces-config.xml---------------------------------
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config><managed-bean> <managed-bean-name>Test</managed-bean-name> <managed-bean-class>MyPackage.Test.DataTest</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean>