如何将Resultset rs对象作为参数传递给Thread

时间:2013-04-19 11:10:46

标签: java jdbc

我是java线程的新手。我的问题是:

我们可以将Resultset rs对象作为参数传递给thread。

我在谷歌搜索,我得到了如何传递字符串,int.But我没有得到如何使用对象参数。

我的示例程序是:

public class dataimport
{
    public dataimport()
    {
        connect(); //this function will connect to database and execute query
    }   

    private void connect()
    {
        /* Connect database
        str="SELECT * FROM tablename"; 
        rs1=statement.executeQuery(str);

        while (rs1.next())
        { 
            /* here each record will pass to each thread run() method*/ 
        }   
    }
}

任何人都可以帮助我。

1 个答案:

答案 0 :(得分:0)

在线程创建的构造函数中设置Object:

public class MyThreadClass implements Runnable {

   public MyThread(Object parameter) {
       // store parameter 
   }

   public void run() {
   //...
   }
}
相关问题