이리도 해보고 저리도 해보고 있습니다. ㅠㅠ  

 

소스.1

 

 import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
   
   
public class NotesDbAdapter { 
   
    public static final String KEY_TITLE = "title"; 
    public static final String KEY_BODY = "body"; 
    public static final String KEY_BODY2 = "body2"; 
    public static final String KEY_ROWID = "_id"; 
   
    private static final String TAG = "NotesDbAdapter"; 
    private DatabaseHelper mDbHelper; 
    private SQLiteDatabase mDb; 
   
    /** 
     * Database creation sql statement 
     */ 
    private static final String DATABASE_CREATE = 
"create table notes (_id integer primary key autoincrement, " 
            + "title text not null, body text not null, body2 text not null);"; 
   
    private static final String DATABASE_NAME = "data"; 
    private static final String DATABASE_TABLE = "notes"; 
    private static final int DATABASE_VERSION = 2; 
   
    private final Context mCtx; 
   
    private static class DatabaseHelper extends SQLiteOpenHelper { 
   
        DatabaseHelper(Context context) { 
            super(context, DATABASE_NAME, null, DATABASE_VERSION); 
        } 
   
        @Override 
        public void onCreate(SQLiteDatabase db) { 
   
            db.execSQL(DATABASE_CREATE); 
        } 
   
        @Override 
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
            Log.w(TAG, "Upgrading database from version " + oldVersion + " to " 
                    + newVersion + ", which will destroy all old data"); 
            db.execSQL("DROP TABLE IF EXISTS notes"); 
            onCreate(db); 
        } 
    } 
   
    public NotesDbAdapter(Context ctx) { 
        this.mCtx = ctx; 
    } 
   
    public NotesDbAdapter open() throws SQLException { 
        mDbHelper = new DatabaseHelper(mCtx); 
        mDb = mDbHelper.getWritableDatabase(); 
        return this; 
    } 
   
    public void close() { 
        mDbHelper.close(); 
    } 
   
    public long createNote(String title, String body, String body2) { 
        ContentValues initialValues = new ContentValues(); 
        initialValues.put(KEY_TITLE, title); 
        initialValues.put(KEY_BODY, body); 
        initialValues.put(KEY_BODY2, body2); 
   
        return mDb.insert(DATABASE_TABLE, null, initialValues); 
    } 
   
    public boolean deleteNote(long rowId) { 
   
        Log.i("Delete called", "value__" + rowId); 
        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0; 
    } 
   
    public Cursor fetchAllNotes() { 
   
        return mDb.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_TITLE, 
                KEY_BODY, KEY_BODY2 }, null, null, null, null, null); 
    } 
   
    public Cursor fetchNote(long rowId) throws SQLException { 
   
        Cursor mCursor = 
   
        mDb.query(true, DATABASE_TABLE, new String[] { KEY_ROWID, KEY_TITLE, 
                KEY_BODY, KEY_BODY2 }, KEY_ROWID + "=" + rowId, null, null, null, null, 
                null); 
        if (mCursor != null) { 
            mCursor.moveToFirst(); 
        } 
        return mCursor; 
   
    } 
   
    public boolean updateNote(long rowId, String title, String body, String body2) { 
        ContentValues args = new ContentValues(); 
        args.put(KEY_TITLE, title); 
        args.put(KEY_BODY, body); 
        args.put(KEY_BODY2, body2); 
   
        return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0; 
    } 
} 

소스.2

 

 import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
   
public class DatabaseTestActivity extends Activity { 
   
    private NotesDbAdapter dbAdapter; 
    private static final String TAG = "NotesDbAdapter"; 
   
        
@Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
   
    Log.d(TAG, "DatabaseTest :: onCreate()"); 
   
    dbAdapter = new NotesDbAdapter(this); 
    dbAdapter.open(); 
   
     Button bt = (Button)findViewById(R.id.button1); 
     bt.setOnClickListener(new View.OnClickListener() { 
   
            public void onClick(View v) { 
                dbAdapter.createNote("title", "body", "body2"); 
                TextView tv = (TextView)findViewById(R.id.textView1); 
                tv.setText("데이터베이스에 넣었습니다."); 
                TextView tv1 = (TextView)findViewById(R.id.textView2); 
                TextView tv2 = (TextView)findViewById(R.id.textView3); 
                tv1.setText("Title과 Body를 데이터베이스에 저장하였습니다."); 
                tv2.setText("얄라숑얄라리얄라"); 
                 Log.d(TAG, "First Button Click"); 
            } 
        }); 
   
        Button bt1 = (Button)findViewById(R.id.button2); 
        bt1.setOnClickListener(new View.OnClickListener() { 
   
            public void onClick(View v) { 
                Cursor result =    dbAdapter.fetchAllNotes(); 
                result.moveToFirst(); 
   
                while(!result.isAfterLast()){ 
                  String title = result.getString(1); 
                  String body = result.getString(2); 
                  String body2 = result.getString(3); 
   
                  TextView tv = (TextView)findViewById(R.id.textView1); 
                  tv.setText(title); 
                  TextView tv1 = (TextView)findViewById(R.id.textView2); 
                  tv1.setText(body); 
                  
                  TextView tv2 = (TextView)findViewById(R.id.textView3); 
                  tv2.setText(body2); 
                  result.moveToNext(); 
   
                } 
                Log.d(TAG, "Second Button Click"); 
                result.close(); 
            } 
        }); 
 } 
}

 

body2를 추가한 상황인데요.

 

내용을 추가하는데는 에러가 없지만..

 

디비에서 출력해올때.. 에러창과 함께 팅깁니다.

 

정말 디피컬트하게 공부해야하는데...... 이같은 예제들을 설명해주는 곳은 없어서 하드하게.. 하나하나 추가해보면서

 

공부를 해보려합니다 도와주세요 ㅠㅠ