-1

AndoirdプロジェクトのSqliteデータベースに日時フィールドを挿入しようとしています。このように多くの方法を試しましたが、日時フィールドを挿入することはできませんでした。ここに事実があります

1]私のSqliteフィールドはタイプtimestampです

2]データベースクラス

package com.gcm.pushandroid;
import java.util.Date;

public class Notifications {

     //private variables 
      String _type; 
      String _time_stamp;


       // Empty constructor 
       public Notifications(){ 

       } 
       // constructor 
       public Notifications(String type, String timeStamp){ 
           this._type = type; 
           this._time_stamp = timeStamp;
       } 


      // getting ID 
      public String getType(){ 
          return this._type; 
       } 

      // setting id 
      public void setType(String type){ 
         this._type = type; 
      } 

     // getting timestamp
     public String getTimeStamp(){ 
        return this._time_stamp; 
     } 

     // setting 
     public void setTimeStamp(String time_stamp){ 
          this._time_stamp = time_stamp; 
     } 

}

3]ここにコードがあります

SQLiteDatabase db = this.getWritableDatabase(); 
ContentValues values = new ContentValues(); 
values.put(KEY_TYPE, notificationObj.getType());  
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
Date date = new Date();
values.put("time_stamp", dateFormat.format(date));
db.insert(TABLE_CONTACTS, null, values); 
db.close();

何が悪いのかわからない。ヘルプに感謝します。ありがとうございました

4

1 に答える 1

1

sqlite フィールド タイプを String / Text に変更する必要があります。タイプ「タイムスタンプ」は許可されません: または - タイムスタンプは整数のみを保持できます

詳細については、http://www.sqlite.org/datatype3.htmlポイント 1.2を参照してください。

于 2012-11-06T21:22:18.137 に答える