Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Main {

    public static boolean isTableExists(SQLiteDatabase db, String tableName) {
        String sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = ? ";
        String paras[] = { tableName };
        try {
            Cursor cursor = db.rawQuery(sql, paras);
            cursor.moveToNext();
            String name = cursor.getString(cursor.getColumnIndex("name"));
            if (name.equals(tableName)) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}