Java 从db2排序的db1中选择值

Java 从db2排序的db1中选择值,java,android,sql,sqlite,Java,Android,Sql,Sqlite,我需要从Android上的两个Sqlite数据库中选择值。值需要按特定顺序排序。值在第一个db中的表产品中,它们的顺序在面向第二个db的表中。当我这样做的时候 Select p.PrdImgURL, cp.PrdID from Products as p inner join CategoryProduct_MM as cp on p.PrdID = cp.PrdID inner join InventoryDB.Facing as f on p.PrdID = f.PrdID wh

我需要从Android上的两个Sqlite数据库中选择值。值需要按特定顺序排序。值在第一个db中的表产品中,它们的顺序在面向第二个db的表中。当我这样做的时候

Select p.PrdImgURL, cp.PrdID 
from Products as p 
inner join CategoryProduct_MM as cp 
on p.PrdID = cp.PrdID 
inner join InventoryDB.Facing as f 
on p.PrdID = f.PrdID 
where cp.CategoryID == 1 and p.PrdImgURL is not null 
order by f.`Order`
我有个错误

android.database.sqlite.SQLiteException:靠近“cp”:语法错误(代码1):

两个数据库位于同一个private/databases/文件夹中。它们不是我做的,我只是用它们

这是我的方法

    private void loadProducts() {
        dbHandler1 dbh1 = dbHandler1.getInstance(this);
        SQLiteDatabase db1 = dbh1.getWritableDatabase();
        db1.execSQL("attach database ? as InventoryDB", new String[]{DB_PATH + DB2_NAME});
        db1.beginTransaction();

        Cursor c = db1.rawQuery("Select p.PrdImgURL, cp.PrdID " +
                "from Products as p " +
                "inner join CategoryProduct_MM as cp " +
                "on p.PrdID = cp.PrdID " +
                "inner join InventoryDB.Facing as f" +
                "on p.PrdID = f.PrdID " +
                "where cp.CategoryID == 1 and p.PrdImgURL is not null "
                "order by f.`Order`", null);
        int count = c.getCount();
        String url[] = new String[count];
        int i = 0;


        while (c.moveToNext()) {
            url[i] = c.getString(c.getColumnIndex("PrdImgURL"));
            i++;
        }
    }
这是dbHandler

public class dbHandler1 extends SQLiteOpenHelper {
    private static final int VERSION = 1;
    private static final String DATABASE_NAME = "SuperupDB.sqlite";
    private static final String TAG = "qwe";
    private static File DATABASE_FILE;

    // This is an indicator if we need to copy the
    // database file.
    private boolean mInvalidDatabaseFile = false;
    private boolean mIsUpgraded = false;
    private Context mContext;

    /**
     * number of users of the database connection.
     */
    private int mOpenConnections = 0;

    private static dbHandler1 mInstance;

    synchronized static public dbHandler1 getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new dbHandler1(context.getApplicationContext());
        }
        return mInstance;
    }

    private dbHandler1(Context context) {
        super(context, DATABASE_NAME, null, VERSION);
        this.mContext = context;
        SQLiteDatabase db = null;
        try {
            db = getReadableDatabase();
            if (db != null) {
                db.close();
            }

            DATABASE_FILE = context.getDatabasePath(DATABASE_NAME);

/*            if (mInvalidDatabaseFile) {
                //copyDatabase();
                Log.d(TAG, "Where is db?");
            }*/
            if (mIsUpgraded) {
                doUpgrade();
            }
        } catch (SQLiteException e) {
        } finally {
            if (db != null && db.isOpen()) {
                db.close();
            }
        }
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //mInvalidDatabaseFile = true;

    }

    @Override
    public void onUpgrade(SQLiteDatabase database,
                          int old_version, int new_version) {
        //mInvalidDatabaseFile = true;
        mIsUpgraded = true;

    }

    /**
     * called if a database upgrade is needed
     */
    private void doUpgrade() {
        // implement the database upgrade here.
    }

    @Override
    public synchronized void onOpen(SQLiteDatabase db) {
        super.onOpen(db);
        // increment the number of users of the database connection.
        mOpenConnections++;
        if (!db.isReadOnly()) {
            // Enable foreign key constraints
            db.execSQL("PRAGMA foreign_keys=ON;");
        }
    }

    /**
     * implementation to avoid closing the database connection while it is in
     * use by others.
     */
    @Override
    public synchronized void close() {
        mOpenConnections--;
        if (mOpenConnections == 0) {
            super.close();
        }
    }

    private void setDatabaseVersion() {
        SQLiteDatabase db = null;
        try {
            db = SQLiteDatabase.openDatabase(DATABASE_FILE.getAbsolutePath(), null,
                    SQLiteDatabase.OPEN_READWRITE);
            db.execSQL("PRAGMA user_version = " + VERSION);
        } catch (SQLiteException e) {
        } finally {
            if (db != null && db.isOpen()) {
                db.close();
            }
        }
    }

}

问题是
f
on
之间没有空格,请参见下文:

    "inner join InventoryDB.Facing as f" +
    "on p.PrdID = f.PrdID " +
尝试按以下方式编写查询:

    Cursor c = db1.rawQuery("Select p.PrdImgURL, cp.PrdID " +
        "from Products as p " +
        "inner join CategoryProduct_MM as cp " +
        "on p.PrdID = cp.PrdID " +
        "inner join InventoryDB.Facing as f " +
        "on p.PrdID = f.PrdID " +
        "where cp.CategoryID == 1 and p.PrdImgURL is not null " +
        "order by f.`Order`", null);