2013-08-14 4 views
-1

초심자 인 것 같습니다.SQL에서 레코드를 가져 오는 방법

하나의 페이지에 데이터를 저장하고 다른 페이지에 데이터를 가져 오는 간단한 앱이 있습니다. 같은 열을 찾을 수 없다는 내용의 데이터를 가져 오려고 시도 할 때 오류가 계속 발생합니다. 내가

 TextView bn = (TextView) findViewById(R.id.budget_need); 


    DatabaseAdapter databaseAdapter = new DatabaseAdapter(getApplicationContext()); 
     databaseAdapter.open(); 
     bn.setText(databaseAdapter.fetchRecordS(1)); 
     databaseAdapter.close(); 

코드 내 databaseAdapter.java

에서 데이터를 가져 오는 곳에서, EnterDetails.java이 내가 데이터를 입력 곳에서 내 코드입니다

  @Override 
     public void onClick(View arg0) { 
      EditText holdersala = (EditText) findViewById(R.id.rawsalary); 
      EditText wantspercentage = (EditText) findViewById(R.id.wantspercent); 
      EditText needspercentage = (EditText) findViewById(R.id.needspercent); 

      String holdersalary = holdersala.getText().toString(); 
      final int salary = Integer.parseInt(holdersalary); 

      String holderwantsp = wantspercentage.getText().toString(); 
      final int wantsp = Integer.parseInt(holderwantsp); 

      String holderneedsp = needspercentage.getText().toString(); 
      final int needsp = Integer.parseInt(holderneedsp); 

      if(wantsp + needsp <= 100){ 

       DatabaseAdapter databaseAdapter = new DatabaseAdapter(getApplicationContext()); 
       databaseAdapter.open(); 
       databaseAdapter.createRecordS(salary); 
       databaseAdapter.createRecordW(wantsp); 
       databaseAdapter.createRecordN(needsp); 
       databaseAdapter.close(); 

       startActivity(new Intent(EnterDetails.this, Summary.class)); 
      } else { 
      } 

      Toast toast = Toast.makeText(EnterDetails.this, "incorrect data", 5000); 
      toast.setGravity(Gravity.CENTER, 0, 0); 
      toast.show(); 
     } 
    }); 

코드를 도와주세요

public class DatabaseAdapter { 

private Context context; 
private SQLiteDatabase database; 
private DatabaseOpenHelper dbHelper; 

public DatabaseAdapter(Context context) { 
    this.context = context; 
} 
public DatabaseAdapter open() throws SQLException { 
    dbHelper = new DatabaseOpenHelper(context); 
    database = dbHelper.getWritableDatabase(); 
    return this; 
} 

public void close() { 
    dbHelper.close(); 
} 
public long createRecordS(int interger) { 
    ContentValues contentValue = new ContentValues();   
    contentValue.put("salafig", interger);    
    return database.insert("maindata", null, contentValue); 
} 
public long createRecordN(int interger) { 
    ContentValues contentValue = new ContentValues();   
    contentValue.put("needsper", interger);    
    return database.insert("maindata", null, contentValue); 
} 
public long createRecordW(int interger) { 
    ContentValues contentValue = new ContentValues();   
    contentValue.put("wantsper", interger);    
    return database.insert("maindata", null, contentValue); 
} 
public int fetchRecordS(long rowId) throws SQLException { 
    Cursor mCursor = database.query(true, "maindata", new String[] { "salafig", 
      "needsper", "wantsper" }, "salafig"+ rowId, null, null, null, null, null); 
    if (mCursor != null) { 
     mCursor.moveToFirst(); 
     return (mCursor.getInt(1)); 
    } 
    return (Integer) null; 
} 
public int fetchRecordW(long rowId) throws SQLException { 
    Cursor mCursor = database.query(true, "maindata", new String[] { "salafig", 
      "needsper", "wantsper" }, "wantsper"+ rowId, null, null, null, null, null); 
    if (mCursor != null) { 
     mCursor.moveToFirst(); 
     return (mCursor.getInt(1)); 
    } 
    return (Integer) null; 
}public int fetchRecordN(long rowId) throws SQLException { 
    Cursor mCursor = database.query(true, "maindata", new String[] { "salafig", 
      "needsper", "wantsper" }, "needsper"+ rowId, null, null, null, null, null); 
    if (mCursor != null) { 
     mCursor.moveToFirst(); 
     return (mCursor.getInt(1)); 
    } 

도움이 필요하시면 미리 감사드립니다.

답변

0

Look at HERE SQLiteDatabase 쿼리 메서드의 올바른 구문을 확인하십시오. 대신이의

"salafig = "+ rowId" 

: 이 방법의 네 번째 매개 변수는 선택 조건은,이 같은 있어야 s입니다 난 당신이 데이터베이스 테이블을 유지하기 위해 일정을 만들 조언

"salafig"+ rowId" 
+0

및 예 : ** public static final String COLUMN_SALAFIG \t = "salafig"; ** 그렇지 않으면 이러한 종류의 문제를 디버깅 할 것입니다. –

관련 문제