首页 \ 问答 \ Cursor在AsyncTask的PreparedStatement上实现(Cursor implement on PreparedStatement in AsyncTask)

Cursor在AsyncTask的PreparedStatement上实现(Cursor implement on PreparedStatement in AsyncTask)

所以我想实现一个光标到我的类,所以我可以填充我的数据网格(不知道这是否正确的方式来做到这一点,当我需要使用可调用SP和准备语句)得到一个

DataGridActivity.Itemnumber不是抽象的,并且不会覆盖Cursor中的抽象方法响应(Bundle)

我不知道如何实现这里的抽象方法,因为我正常使用getstring methode为我准备好的语句想知道是否有某种方式可以做到这一点,而不是使用光标填充我的网格

public class Itemnumber extends AsyncTask<String,String,String> implements Cursor {
    String z = "";
    @Override
    protected void onPreExecute() {
    }
    @Override
    protected void onPostExecute(String r) {
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            Connection con = connectionClass.CONN();
            if (con == null) {
                z = "Error in connection with SQL server";
            } else {
                PreparedStatement preparedStatement = null;
                String sqli = "select ID,ItemNumber,Trashed,Sold from [file].[Item] where [ItemNumber] =?";
                preparedStatement = con.prepareStatement(sqli);
                preparedStatement.setString(1, "test");
                ResultSet rs = preparedStatement.executeQuery();
                if (rs.next()) {
                } else {
                }
            }
        } catch (Exception ex) {
            z = "Exceptions";
        }
        return z;
    }
    @Override
    public Bundle respond(Bundle extras){
        moveToFirst();
        return Bundle.EMPTY;
    }
}

我的Datagrid活动类

Cursor csr = new Itemnumber();
//create DataTable object
DataTable dtDataSource = new DataTable();
//define column
dtDataSource.addAllColumns(new String[]{"column_1", "column_2","column_3", "column_4});
//create DataRow
DataTable.DataRow drRow;

//populate data from cursor into DataSource
if(csr.moveToFirst()){
    do{
        drRow = dtDataSource.newRow();
        drRow.set("column_1", csr.getString(csr.getColumnIndex("field_1")));
        drRow.set("column_2", csr.getString(csr.getColumnIndex("field_2")));
        drRow.set("column_2", csr.getString(csr.getColumnIndex("field_3")));
        drRow.set("column_4", csr.getString(csr.getColumnIndex("field_4")));

        dtDataSource.add(drRow);
    } while(csr.moveToNext());
    csr.close();
}        
/**
 *  Prepare the DataGrid
 */
//initialize DataGrid
DataGrid dg = (DataGrid)findViewById(R.id.datagrid);
//define column style, bond each DataGrid column by DataTable column
dg.addColumnStyles(new DataGrid.ColumnStyle[]{
        new DataGrid.ColumnStyle(getString(R.string.ID), "column_1", 80),
        new DataGrid.ColumnStyle(getString(R.string.ItemNumber), "column_2", 120),
        new DataGrid.ColumnStyle(getString(R.string.Trashed), "column_3", 100),
        new DataGrid.ColumnStyle(getString(R.string.Sold), "column_4", 150)    
});
//set the DataTable as source
dg.setDataSource(dtDataSource);
//generate the DataGrid
dg.refresh();

So I am trying to implement a Cursor to my class so i can populate my datagrid (not sure if that is the right way to do it when i need to use callable for SP and prepared statement) which i made from this guide here but i gets a

DataGridActivity.Itemnumber is not abstract and does not override abstract method respond(Bundle) in Cursor

i am not sure how to implement the abstract method here as i normaly use getstring methode for my prepared statements wonder if there is somehow i could do that instead to populate my grid instead of using the Cursor

public class Itemnumber extends AsyncTask<String,String,String> implements Cursor {
    String z = "";
    @Override
    protected void onPreExecute() {
    }
    @Override
    protected void onPostExecute(String r) {
    }

    @Override
    protected String doInBackground(String... params) {
        try {
            Connection con = connectionClass.CONN();
            if (con == null) {
                z = "Error in connection with SQL server";
            } else {
                PreparedStatement preparedStatement = null;
                String sqli = "select ID,ItemNumber,Trashed,Sold from [file].[Item] where [ItemNumber] =?";
                preparedStatement = con.prepareStatement(sqli);
                preparedStatement.setString(1, "test");
                ResultSet rs = preparedStatement.executeQuery();
                if (rs.next()) {
                } else {
                }
            }
        } catch (Exception ex) {
            z = "Exceptions";
        }
        return z;
    }
    @Override
    public Bundle respond(Bundle extras){
        moveToFirst();
        return Bundle.EMPTY;
    }
}

My Datagrid activity class

Cursor csr = new Itemnumber();
//create DataTable object
DataTable dtDataSource = new DataTable();
//define column
dtDataSource.addAllColumns(new String[]{"column_1", "column_2","column_3", "column_4});
//create DataRow
DataTable.DataRow drRow;

//populate data from cursor into DataSource
if(csr.moveToFirst()){
    do{
        drRow = dtDataSource.newRow();
        drRow.set("column_1", csr.getString(csr.getColumnIndex("field_1")));
        drRow.set("column_2", csr.getString(csr.getColumnIndex("field_2")));
        drRow.set("column_2", csr.getString(csr.getColumnIndex("field_3")));
        drRow.set("column_4", csr.getString(csr.getColumnIndex("field_4")));

        dtDataSource.add(drRow);
    } while(csr.moveToNext());
    csr.close();
}        
/**
 *  Prepare the DataGrid
 */
//initialize DataGrid
DataGrid dg = (DataGrid)findViewById(R.id.datagrid);
//define column style, bond each DataGrid column by DataTable column
dg.addColumnStyles(new DataGrid.ColumnStyle[]{
        new DataGrid.ColumnStyle(getString(R.string.ID), "column_1", 80),
        new DataGrid.ColumnStyle(getString(R.string.ItemNumber), "column_2", 120),
        new DataGrid.ColumnStyle(getString(R.string.Trashed), "column_3", 100),
        new DataGrid.ColumnStyle(getString(R.string.Sold), "column_4", 150)    
});
//set the DataTable as source
dg.setDataSource(dtDataSource);
//generate the DataGrid
dg.refresh();

原文:https://stackoverflow.com/questions/41642997
更新时间:2023-12-21 10:12

最满意答案

我已经想出了如何做到这一点。

public class func createSharedManager(baseURL: NSURL!) -> ZRUserAuthenticationHTTPSessionManager {
  StaticManager.instance = ZRUserAuthenticationHTTPSessionManager(baseURL: baseURL)

  return StaticManager.instance!
}

public class var sharedManager: ZRUserAuthenticationHTTPSessionManager? {
  return StaticManager.instance
}

private struct StaticManager {
 static var instance: ZRUserAuthenticationHTTPSessionManager? = nil
}

I've figured out how to do this.

public class func createSharedManager(baseURL: NSURL!) -> ZRUserAuthenticationHTTPSessionManager {
  StaticManager.instance = ZRUserAuthenticationHTTPSessionManager(baseURL: baseURL)

  return StaticManager.instance!
}

public class var sharedManager: ZRUserAuthenticationHTTPSessionManager? {
  return StaticManager.instance
}

private struct StaticManager {
 static var instance: ZRUserAuthenticationHTTPSessionManager? = nil
}

相关问答

更多
  • 对我来说这是最好的方法,让init私有。 // MARK: - Singleton final class Singleton { // Can't init is singleton private init() { } // MARK: Shared Instance static let shared = Singleton() // MARK: Local Variable var emptyStringArray : [String] = ...
  • 它的速度非常简单 class SharedManager { static let sharedInstance = SharedManager() var pic = UIImage() } 并访问它 SharedManager.sharedInstance.pic = UIImage(named: "imagename")! 这里是关于单身人士的很好的指导 https://github.com/hpique/SwiftSingleton https://thatthinginswi ...
  • 我已经想出了如何做到这一点。 public class func createSharedManager(baseURL: NSURL!) -> ZRUserAuthenticationHTTPSessionManager { StaticManager.instance = ZRUserAuthenticationHTTPSessionManager(baseURL: baseURL) return StaticManager.instance! } public class var shar ...
  • 目前我只能想象你不打电话 GameController.sharedInstance.onProblemSolved() 当你想将一个String追加到problemsSolved 。 您还应该考虑在GameController您的函数和变量GameController静态。 如果这不能解决您的问题,我需要更多关于如何以及何时向problemsSolved添加内容的信息。 At the moment I only can imagine that you don't call GameController ...
  • 编辑:正如评论中所讨论的,这仅适用于NSObject的子类。 在这个答案的时候,没有办法通过IB访问“纯粹的”Swift课程。 您可以将“对象”项拖到IB中,并为其指定一个Swift类。 从IB调色板中选择“对象”: 将其拖动到左侧边栏上的视图控制器下: 并在右侧的对象检查器中将其分配给您的类: Edit: As discussed in the comments, this works only if you subclass NSObject. At the time of this answer th ...
  • 此模式不保证只有一个Global类的实例。 它只允许任何人通过其sharedinstance属性访问Global的单个公共实例。 所以Global()声明了Global类的新实例。 但是Global.sharedinstance不会创建Global的新实例,只是获取预先创建的实例(在第一次访问它时创建)。 (如果你改变你的b声明来读取var b = Global.sharedinstance你会看到它确认a和b指向同一个实例。) 如果要禁止创建Global的其他实例,请将其init private: ...
  • 更新: Xcode 8.2.1•Swift 3.0.2 extension Double { static let twoFractionDigits: NumberFormatter = { let formatter = NumberFormatter() formatter.numberStyle = .decimal formatter.minimumFractionDigits = 2 formatter.maximumFra ...
  • 你在开发人员洞穴中听到的一个常见短语是“我知道单身人士不好但是......” ,似乎几乎有人认为单身人士“不好”,但我们看到苹果公司和第三方开发商都在使用它们,在他们的应用程序和共享框架中。 所以你可能会问为什么我们使用单身人士。 我会让你进去。 Apple使用它们! 作为第三方开发者,我们期待苹果公司获得“最佳实践”,而苹果公司所采用的任何模式都是社区普遍采用的 方便 。 单身人士允许你从任何地方访问一个物体 class LoginController: UIViewController { ...
  • 你不能相信扩展你的类来创建自己的单个实例1 :即使你能以某种方式确保它们都实现了getInstance ,也没有办法告诉那个方法,他们在构造一个新的自己的实例之前检查了inst 。 保持对进程的控制:创建Map ,并实例化通过反射2传入的类。 现在,您的代码可以决定是否创建实例,而不依赖于子类的getInstance 。 1一句流行的说法是,“如果你想做一份正确的工作,那就去做吧。” 2这是一个描述基于setAccessible(true)的解决方案的链接 setAccessible ...
  • 扩展 extension AWSclass { func functionA () { ...} } 用法 AWSclass.shared.functionA() To extend extension AWSclass { func functionA () { ...} } usage AWSclass.shared.functionA()

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)