can column name be number in SQLite?

330
May 01, 2017, at 09:22 AM

I am developing an android aplication and used an external database with 70 rows and 100 columns. for each row, when My app user clicks on next button, the app goes to next column of database and shows it's content. So I must use numbers of 1 to 100 for my column's name to refer to selected column by increas or decreas it's number. but it occures error in eclipse. for example in ID = 1, when I select "mani" column, it works like a charm but shows nothing for "1" column.

Database Class :
package com.codegostarNiloo.negar;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class Database extends SQLiteOpenHelper {
public static String   DB_PATH;
public static String   DB_NAME = "negar.db";
private SQLiteDatabase myDataBase;
private final Context  myContext;

public Database(Context context) {
    super(context, DB_NAME, null, 1);
    this.myContext = context;
    DB_PATH = "/data/data/" + context.getPackageName() + "/" + "databases/";
}

public void createDataBase() throws IOException {
    copyDataBase();
    Log.d("isexist", "" + checkDataBase());
}

private boolean checkDataBase() {
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READONLY);
    }
    catch (SQLiteException e) {}
    if (checkDB != null) {
        checkDB.close();
    }
    return checkDB != null ? true : false;
}

private void copyDataBase() throws IOException {
    File dir = new File(DB_PATH);
    if ( !dir.exists()) {
        dir.mkdirs();
    }
    File database = new File(dir, DB_NAME);
    if ( !database.exists()) {
        InputStream myInput = myContext.getAssets().open(DB_NAME);
        String outFileName = DB_PATH + DB_NAME;
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }
        myOutput.flush();
        myOutput.close();
        myInput.close();
    }
}

public void openDataBase() throws SQLException {
    // Open the database
    String myPath = DB_PATH + DB_NAME;
    // SQLiteDatabase.NO_LOCALIZED_COLLATORS
    myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);
}

@Override
public synchronized void close() {
    if (myDataBase != null)
        myDataBase.close();
    super.close();
}

@Override
public void onCreate(SQLiteDatabase arg0) {
    // TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub
 }
}

MainActivity Class:

// database method :
    private void Database() throws Error {
    myDbHelper = new Database(MainActivity.this);
    try {
        myDbHelper.createDataBase();
    }
    catch (IOException ioe) {
        throw new Error("Unable to create database");
    }
    try {
        myDbHelper.openDataBase();
    }
    catch (SQLException sqle) {
        throw sqle;
    }
}
// Select column 1 of row 1:
database();
db = myDbHelper.getWritableDatabase();
Cursor c = db.rawQuery("select * from mohtava where ID = " + 1, null);
    if (c.moveToNext()) {
    String j=c.getString(c.getColumnIndex("1"));
        } 
db.close();
c.close();

database : http://www.axgig.com/images/23013560911355303754.jpg

error : http://www.axgig.com/images/89351172061788690795.jpg

READ ALSO
Using Cocos in Xamarin Android

Using Cocos in Xamarin Android

I'm trying to use Cocos in Xamarin Android AppI would like to create simple window and display an object from png file, but I got only a blank screen

434
Read “Location” object from firebase database android

Read “Location” object from firebase database android

I am able to read and retrieve String, double, custom objects from firebase database but am not able to read Location object specifically

316
What code do you need to type in order to add the soundcloud library to an app?

What code do you need to type in order to add the soundcloud library to an app?

So basically, I want to be able to search the entire SoundCloud library and add music to the app, so it can playI chose SoundCloud because it is open source

288