Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
JSF Webgrid working with ResultSetDataModel
posted

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.

Parents
  • 1324
    Suggested Answer
    posted

    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;
      }
    }

Reply Children