Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.ContentValues;
import android.database.sqlite.SQLiteStatement;
import java.util.Set;
import java.util.TreeSet;

public class Main {
    public static void bindValores(SQLiteStatement statement, ContentValues contentValues) {
        Set<String> chaves = new TreeSet<>(contentValues.keySet());
        int index = 1;

        for (String chave : chaves) {
            Object valor = contentValues.get(chave);

            if (valor == null) {
                statement.bindNull(index);

            } else if (valor instanceof String) {
                statement.bindString(index, (String) valor);

            } else if (valor instanceof Double || valor instanceof Float) {
                statement.bindDouble(index, Double.valueOf(String.valueOf(valor)));

            } else if (valor instanceof Integer || valor instanceof Long) {
                statement.bindLong(index, Long.valueOf(String.valueOf(valor)));
            } else if (valor instanceof byte[]) {
                statement.bindBlob(index, (byte[]) valor);
            }
            index++;
        }
    }
}