我正在尝试配置一个简单的SQLiteOpenHelper
,并在执行时出错。
错误是:
表
ogrenci
没有名为的列field__final
编译时:
INSERT INTO ogrenci(field__final, field__numarasi, field_ad, field__vize, field__soyad) VALUES(?, ?, ?, ?, ?);
我无法弄清楚是什么问题?
dbSQLite.java
班级 :
package com.example.sqllitevt;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class dbSQLite extends SQLiteOpenHelper {
private static final String VERITABANI = "ogrenciler";
private static final String TABLO_ADI = "ogrenci";
private static final String KISI_ADI = "field_ad";
private static final String KISI_SOYADI = "field__soyad";
private static final String KISI_NUMARASI = "field__numarasi";
private static final String KISI_VIZE = "field__vize";
private static final String KISI_FINAL = "field__final";
private static int SURUM = 1;
public dbSQLite(Context context) {
super(context, VERITABANI, null, SURUM);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String sql = "CREATE TABLE " + TABLO_ADI + " ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ KISI_ADI + " TEXT NOT NULL,"
+ KISI_SOYADI + " TEXT NOT NULL,"
+ KISI_NUMARASI + " TEXT"
+ KISI_VIZE + "TEXT"
+ KISI_FINAL + "TEXT" + ");";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion >= newVersion)
return;
String sql = null;
if (oldVersion == 1)
sql = "alter table " + TABLO_ADI + " add note text;";
if (oldVersion == 2)
sql = "";
Log.d("EventsData", "onUpgrade : " + sql);
if (sql != null)
db.execSQL(sql);
}
public void kaydet(String k_ad, String k_soyad, String k_numara,
String k_vize, String k_finali) {
try{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(this.KISI_ADI, k_ad);
cv.put(this.KISI_SOYADI, k_soyad);
cv.put(this.KISI_NUMARASI, k_numara);
cv.put(this.KISI_VIZE, k_vize);
cv.put(this.KISI_FINAL, k_finali);
db.insertOrThrow(this.TABLO_ADI,null,cv);
Log.d("DB->Basarili","Basarılı");
db.close();
}catch(SQLiteException ex){
Log.e("DB->Kayit", "Basarisiz oldu:"+ex.getMessage() );
}
}
}
ekle.java
班级:
package com.example.sqllitevt;
import android.os.Bundle; import android.app.Activity; import android.text.Editable; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TabHost; import android.widget.TabHost.TabSpec; import android.widget.Toast;
public class ekle extends Activity { dbSQLite db; Button kaydet; EditText ad,soyad,numara,vize,finali;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sekme_ekle);
kaydet=(Button) findViewById(R.id.btnKaydet);
ad=(EditText)findViewById(R.id.txtAd);
soyad=(EditText)findViewById(R.id.txtSoyad);
numara=(EditText)findViewById(R.id.txtNumara);
vize=(EditText)findViewById(R.id.txtVize);
finali=(EditText)findViewById(R.id.txtFinal);
kaydet.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
db=new dbSQLite(getApplicationContext());
String k_ad=ad.getText().toString();
String k_soyad=soyad.getText().toString();
String k_numara=numara.getText().toString();
String k_vize= vize.getText().toString();
String k_finali=finali.getText().toString();
db.kaydet(k_ad, k_soyad, k_numara ,k_vize,k_finali);
Toast.makeText(getApplicationContext(), "Kayıt Edildi", Toast.LENGTH_LONG).show();
} });
} }