안드로이드 개발 질문/답변
(글 수 45,052)
C:\Users\k\Desktop\workspace\DataBaseTest\src\test\kwj\database\DataBaseTestActivity.java
public class DataBaseTestActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SQLiteDatabase db = SQLiteDatabase.create(null);
db.execSQL("CREATE TABLE test( id int(11), content char(10));");
System.out.println("Create table is done");
db.execSQL("INSERT INTO test ( id, content) VALUES (1, 'a'),(2, 'b'),(3, 'c'),(4, 'd'),(5, 'e'),(6, 'f'),(7, 'g'),(8, 'h'),(9, 'i');");
Cursor cursor = db.rawQuery("select * from test;", null);
TextView tv1 = (TextView) findViewById(R.id.main_text1);
TextView tv2 = (TextView) findViewById(R.id.main_text2);
tv1.setText(cursor.getInt(0));
tv2.setText(cursor.getString(1));
}
}
이렇게 적으니까 로그캣에
05-26 21:11:18.284: E/AndroidRuntime(14459): Caused by: android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: INSERT INTO test ( id, content) VALUES (1, 'a'),(2, 'b'),(3, 'c'),(4, 'd'),(5, 'e'),(6, 'f'),(7, 'g'),(8, 'h'),(9, 'i');
라는 말이 뜨던데............ 도와주세요
코드 하이라이터 어떻게 쓰는지 잘 모르겠네요..
* ps : 공지사항을 다 읽었음 이라는 말을 적어야 한다더군요...?
2012.05.26 21:49:03
db.execSQL("INSERT INTO test ( id, content) VALUES (1, 'a')");
db.execSQL("INSERT INTO test ( id, content) VALUES (2, 'b')");
db.execSQL("INSERT INTO test ( id, content) VALUES (3, 'c')");
db.execSQL("INSERT INTO test ( id, content) VALUES (4, 'd')");
db.execSQL("INSERT INTO test ( id, content) VALUES (5, 'e')");
db.execSQL("INSERT INTO test ( id, content) VALUES (7, 'g')");
db.execSQL("INSERT INTO test ( id, content) VALUES (8, 'h')");
db.execSQL("INSERT INTO test ( id, content) VALUES (9, 'i')");