마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

int형 변수를 DB로 넘기고 싶은데 방법을 알고싶습니다.

0 추천
package com.book.minipangkakao;
 
import android.app.*;  
import android.content.Intent;
import android.database.*;  
import android.os.Bundle;  
import android.util.*;  
import android.view.*;  
import android.view.View.*;  
import android.widget.*;
 
public class TestInput extends Activity implements OnClickListener{
DBHandler dbHandler;  
    EditText edtName;  
    Cursor cursor = null;  
    String[] arr = null; 
    TextView tvi;
    MainView mainview;
    int s = 0;
    public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);  
        setContentView(R.layout.testrank);
        
        Button btn = (Button)findViewById(R.id.button1);          
        btn.setOnClickListener(this);  
        
        s = MainView.score;
        s *=100;
        
        edtName = (EditText)findViewById(R.id.editText1);
        TextView tvi = (TextView)findViewById(R.id.textView3);
        tvi.setText(" "+s);
    }
    
    public void onClick(View v){
    dbHandler = DBHandler.open(this);
   
    try {                          
            long re = dbHandler.insert(  
                    edtName.getText().toString(),   
                    tvi.getText().toString());
            if(re == 0){  
                Toast.makeText(this, "추가 실패", 2000).show();  
            }else{  
                Toast.makeText(this, "추가 성공", 2000).show();  
                cursor = dbHandler.selectAll();  
                arr = new String[cursor.getCount()];  
                int count = 0;  
                while(cursor.moveToNext()){  
                    String code = cursor.getString(0);  
                    String sang = cursor.getString(1);  
                    String price = cursor.getString(2);  
                    arr[count] = code + " " + sang + " " + price;  
                    count++;  
                }  
                cursor.close();  
                  
              
            }            
    } catch (Exception e) {  
        Log.i("disp", "err:" + e);  
    }
    Intent intent2 = new Intent(TestInput.this, ListTest.class);
    startActivity(intent2);
    }
}
 
s값을 DB핸들러로 넘기고 싶은데 작동은 하지만 안넘어가네요... 방법이 없을까요?? 에디트 텍스트껀 잘 넘어가는데..
이거때문에 하루종일 골머리썩고있네요 ㅠ
코딩잘하고싶다 (980 포인트) 님이 2013년 7월 2일 질문

1개의 답변

0 추천
DBHandler.insert 의 두번째 파라미터로 넘겨받은 값을 기록할 디비 컬럼이 TEXT가 아닌가 보네요.
DrKein (870 포인트) 님이 2013년 7월 2일 답변
그럼 DB 컬럼을 어떤걸로 바꿔줘야 할까요?? 일단 DB 컬럼이 텍스트이면 저 소스에서 s값이 넘어가나요??
...