Search code examples
androidjdbccursor

ResultSet to Android Cursor


I my connecting to a MySQL database that is on PC from my android application.

I am using java.sql.jdb for that. Now I want my result set to get in android.database.cursor??

How can I do that..?? Thats my code I am using in android application its getting the results for database but can't cast to Cursor:

    Connection connect = null;
    ResultSet resultSet = null;
    Statement statement = null;

    try {
        connect = DriverManager.getConnection("jdbc:mysql://"+DbHelper.DB_Path+"/"+DbHelper.DB_Name+"?"
                + "user="+ DbHelper.DB_UserName+ "&password="+ DbHelper.DB_Pass);


        statement = connect.createStatement();
        // Result set get the result of the SQL query
        resultSet = statement
                .executeQuery("Select * from btag_store "+
                        "Where "+
                        "guid='"+filterArgs+"'");


        }
    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    Cursor cc;
    cc = (Cursor) resultSet; // error in type casr

I know that type casting will give me error, but is there any other way for that..??

Thanks


Solution

  • To put it simply, you cannot. Unless you are willing to do all the work to define an object that implements the Cursor interface and uses a ResultSet to fulfil Cursor's implementation details. That would be somewhat silly, though, as the ResultSet object is already designed to iterate over results returned from the database. The cleanest approach is to use the ResultSet object as it was intended.