アプリケーションで複数のテーブルを持つデータベースを使用しています。解析中に2つのテーブルにデータを書き込む必要があるXMLパーサーがあります。両方のテーブル用に2つのデータベースアダプタを作成しましたが、問題が発生しました。1つのテーブルで作業している場合、それは簡単です。
FirstDBAdapter firstTable = new FirstDBAdapter(mycontext);
firstTable.open(); // open and close it every time I need to insert something
// may be hundreds of times while parsing
// it opens not a table but whole DB
firstTable.insertItem(Item);
firstTable.close();
これはSAXパーサーであるため、私の意見では(おそらく私は間違っています)、これはさらに優れています。
FirstDBAdapter firstTable = new FirstDBAdapter(mycontext);
@Override
public void startDocument() throws SAXException
{
firstTable.open(); // open and close only once
}
...
firstTable.insertItem(Item);
...
@Override
public void endDocument() throws SAXException
{
firstTable.close();
}
しかし、2番目のテーブルにデータを挿入する必要がある場合はどうすればよいですか?たとえば、2つ目のアダプターがある場合、これは悪い考えだと思います。
FirstDBAdapter firstTable = new FirstDBAdapter(mycontext);
SecondDBAdapter secondTable = new SecondDBAdapter(mycontext);
@Override
public void startDocument() throws SAXException
{
firstTable.open();
secondTable.open();
}
これを達成する方法について何か考えはありますか?