データベースから特定のフィールドからPDFへのレポートを取得しようとしています。 pdfは完全に生成されていますが、すべてのエントリではなく、データベースからの最初のエントリの読み取りだけです。カーソルをSQLiteデータベースから次の行に読み込む方法は?
これはPDFのために私のコードです:これは私のDBHelperクラスからデータを引っ張っている
public void exportDataBaseIntoPDF() {
Document doc = new Document(PageSize.A4);
try {
path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/MSS Jobsheets";
date = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());
File dir = new File(path);
if (!dir.exists())
dir.mkdirs();
Log.d("PDFCreator", "PDF Path: " + path);
filePDF = new File(dir, "Report" + "(" + date + ")" + ".pdf");
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(filePDF);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
PdfWriter.getInstance(doc, fOut);
doc.open();
DBHelper db = new DBHelper(this);
Cursor cursor = db.getDataItem();
int count = cursor.getCount();
cursor.moveToFirst();
for (int j = 0; j < count; j++) {
PdfPTable table = new PdfPTable(2);
table.addCell(cursor.getString(cursor.getColumnIndex("name")));
table.addCell(cursor.getString(cursor.getColumnIndex("gender")));
cursor.moveToNext();
doc.add(table);
doc.close();
}
} catch (DocumentException e) {
e.printStackTrace();
}
}
:
public Cursor getDataItem() {
SQLiteDatabase db = this.getReadableDatabase();
String q = "SELECT * FROM " + PERSON_TABLE_NAME;
Cursor mCursor = db.rawQuery(q, null);
return mCursor;
}
}
をしかし、私は言ったように、それが唯一のデータベースから最初の行を読み込み、データを追加しますが、データベースの次の行に移動せずにPDFにデータを追加します。
この問題をお手伝いできますか? ありがとうございます!
の外に次の行を入れて使用すると、データベースに複数の行を持っていますか? –
はい、私は持っています。基本的にフォームのユーザーが記入すると、その日の終わりに、ユーザーは特定のフィールドからレポートを取り込んで電子メールを送信できます。 – Newbie
doc out forループを閉じるようにしてください。この行を書くdoc.close();ループの外側に – Munir