安卓(Android) 怎么将游标(Cursor)当前行的内容打印到system.out

2019年10月30日21:50:38安卓(Android) 怎么将游标(Cursor)当前行的内容打印到system.out已关闭评论 1,013 967字阅读3分13秒

1.简介

安卓(Android) 怎么将游标(Cursor)当前行的内容打印到system.out?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import java.io.PrintStream;

import android.database.Cursor;
import android.database.sqlite.SQLiteException;

public class Main {
  
  public static void dumpCurrentRow(Cursor cursor) {
    dumpCurrentRow(cursor, System.out);
  }

  
  public static void dumpCurrentRow(Cursor cursor, PrintStream stream) {
    String[] cols = cursor.getColumnNames();
    stream.println("" + cursor.getPosition() + " {");
    int length = cols.length;
    for (int i = 0; i < length; i++) {
      String value;
      try {
        value = cursor.getString(i);
      } catch (SQLiteException e) {
        
        
        
        value = "<unprintable>";
      }
      stream.println("   " + cols[i] + '=' + value);
    }
    stream.println("}");
  }

  
  public static void dumpCurrentRow(Cursor cursor, StringBuilder sb) {
    String[] cols = cursor.getColumnNames();
    sb.append("" + cursor.getPosition() + " {\n");
    int length = cols.length;
    for (int i = 0; i < length; i++) {
      String value;
      try {
        value = cursor.getString(i);
      } catch (SQLiteException e) {
        
        
        
        value = "<unprintable>";
      }
      sb.append("   " + cols[i] + '=' + value + "\n");
    }
    sb.append("}\n");
  }
}

 
继续阅读
编程十万个怎么办