将数据插入DataBase时出错

时间:2012-08-04 10:09:06

标签: android sqlite

我有使用EditText获取数据的表单活动并通过DataBase Helper将该数据插入DataBase。 在我填写表格后按下按钮,异常给我一个错误并说:

  

08-04 13:03:11.527:E / Database(1311):android.database.sqlite.SQLiteException:表数据没有名为equity的列:,编译时:INSERT INTO数据(贷款,castumers,股票,股权) ,fixedAssets,bonds,accumultedDepreciation,etCash,compNameAdd)VALUES(?,?,?,?,?,?,?,?,?);

我无法理解为什么它说我没有股权专栏,我确实有......

这是表格活动:

package com.nituach.nituach;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AddNewBuisness extends Activity implements OnClickListener {
public static String companyName, cash, stock, ought, fixedAssets,
        accumulatedDepreciation, bonds, loans, equity;
TextView tvOt;
EditText cmIn, tvIn1, tvIn2, tvIn3, tvIn4, tvIn5, tvIn6, tvIn7, tvIn8;
Button btn;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.add_new_buisness);
    cmIn = (EditText) findViewById(R.id.etCompanyName);
    tvIn1 = (EditText) findViewById(R.id.etCash);
    tvIn2 = (EditText) findViewById(R.id.etStock);
    tvIn3 = (EditText) findViewById(R.id.etOught);
    tvIn4 = (EditText) findViewById(R.id.etFixedAssets);
    tvIn5 = (EditText) findViewById(R.id.etAccumulatedDepreciation);
    tvIn6 = (EditText) findViewById(R.id.etBonds);
    tvIn7 = (EditText) findViewById(R.id.etLoans);
    tvIn8 = (EditText) findViewById(R.id.etEquity);

    btn = (Button) findViewById(R.id.button1);

    btn.setOnClickListener(AddNewBuisness.this);
}

public void onClick(View v) {
    if (tvIn1.getText().length() >= 1 && tvIn2.getText().length() >= 1
            && tvIn3.getText().length() >= 1
            && tvIn4.getText().length() >= 1
            && tvIn5.getText().length() >= 1
            && tvIn6.getText().length() >= 1
            && tvIn7.getText().length() >= 1
            && tvIn8.getText().length() >= 1) {

        // Integer.parseInt(tvIn3.getText().toString());
        companyName = cmIn.getText().toString();
        cash = tvIn1.getText().toString();
        stock = tvIn2.getText().toString();
        ought = tvIn3.getText().toString();
        fixedAssets = tvIn4.getText().toString();
        accumulatedDepreciation = tvIn5.getText().toString();
        bonds = tvIn6.getText().toString();
        loans = tvIn7.getText().toString();
        equity = tvIn8.getText().toString();

        String cm = companyName;
        String ch = cash;
        String sk = stock;
        String ot = ought;
        String fs = fixedAssets;
        String an = accumulatedDepreciation;
        String bs = bonds;
        String ls = loans;
        String ey = equity;

        DataBase entry = new DataBase(AddNewBuisness.this);
        entry.open();
        entry.createEntry(cm, ch, sk, ot, fs, an, bs, ls, ey);
        entry.close();

        Intent myIntent = new Intent(AddNewBuisness.this,
                NituachActivity.class);
        AddNewBuisness.this.startActivity(myIntent);
    } else {
        // AlertDialog.Builder builder = new
        // AlertDialog.Builder(AddNewBuisness.this);
        // builder.setMessage("dsfkjhlkdfg");

        Intent myIntent = new Intent(AddNewBuisness.this,   
NituachActivity.class);
        AddNewBuisness.this.startActivity(myIntent);
    }

}

}

这是DataBase Helper:

package com.nituach.nituach;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBase {

    public static final String RAW_ID = "_id";
    public static final String RAW_COMPNAMEADD = "compNameAdd";
    public static final String RAW_CASH = "etCash";
    public static final String RAW_CUSTOMERS = "castumers";
    public static final String RAW_STOCK = "stock";
    public static final String RAW_FIXED_ASSETS = "fixedAssets";
    public static final String RAW_ACCUMULTED_DEPRECIATION = "accumultedDepreciation";
    public static final String RAW_BONDS = "bonds";
    public static final String RAW_LOANS = "loans";
    public static final String RAW_EQUITY = "equity";

    public static final String RAW_COMPNAME_ID = "_id";
    public static final String RAW_COMPNAME = "compName";

    private static final String DATABASE_NAME = "ProsseDatBase";
    static final String DATABASE_TABLE = "data";
    static final String DATABASE_TABLE_SETTINGS = "compNameConnector";

    private static final int DATABASE_VERSION = 1;

    private ProsseDatBase thdb;
    private static Context tcontext;
    private SQLiteDatabase tdb;

    private static class ProsseDatBase extends SQLiteOpenHelper {

        public ProsseDatBase(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            String pdb = "CREATE TABLE  " + DATABASE_TABLE + " ( " + RAW_ID
                    + " INTEGER PRIMARY KEY AUTOINCREMENT, " +   
RAW_COMPNAMEADD
                    + "TEXT, " + RAW_CASH + " TEXT, " + RAW_CUSTOMERS
                    + " TEXT, " + RAW_STOCK + " TEXT, " + RAW_FIXED_ASSETS
                    + " TEXT, " + RAW_ACCUMULTED_DEPRECIATION + " TEXT, "
                    + RAW_BONDS + " TEXT, " + RAW_LOANS + " TEXT" + 
RAW_EQUITY
                    + " TEXT );";
            db.execSQL(pdb);

            String cndb = "CREATE TABLE  " + DATABASE_TABLE_SETTINGS + " ( "
                    + RAW_COMPNAME_ID + " INTEGER PRIMARY KEY 
AUTOINCREMENT, "
                    + RAW_COMPNAME + " TEXT );";
            db.execSQL(cndb);

        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
            db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_SETTINGS);
            onCreate(db);
        }
    }

    public DataBase(Context c) {
        tcontext = c;
    }

    public DataBase open() throws SQLiteException {
        thdb = new ProsseDatBase(tcontext);
        tdb = thdb.getWritableDatabase();
        return this;
    }

    public SQLiteDatabase getDatabase() {
        return tdb;
    }

    public void close() {
        tdb.close();
    }

    public long createEntry(String cm, String ch, String sk, String ot,
            String fs, String an, String bs, String ls, String ey) {
        ContentValues cv = new ContentValues();
        cv.put(RAW_COMPNAMEADD, cm);
        cv.put(RAW_CASH, ch);
        cv.put(RAW_CUSTOMERS, ot);
        cv.put(RAW_STOCK, sk);
        cv.put(RAW_FIXED_ASSETS, fs);
        cv.put(RAW_ACCUMULTED_DEPRECIATION, an);
        cv.put(RAW_BONDS, bs);
        cv.put(RAW_LOANS, ls);
        cv.put(RAW_EQUITY, ey);

        return tdb.insert(DATABASE_TABLE, null, cv);
    }




}

0 个答案:

没有答案