データベースに名前を渡しました。この名前を使用して、その名前の詳細を抽出します。私はこれをやろうとしています。どうすれば解決できますか?「name」はクリックされた名前です。このパラメーターを使用してデータベースにクエリを実行し、この名前の関連情報を取得したいと思います。
public String getName(String name) {
// TODO Auto-generated method stub
String namereturned = "";
String[] columns = new String[] { KEY_ROWID, KEY_NAME,
KEY_PERSONALPHONE, KEY_HOMEPHONE, KEY_OFFICEPHONE };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_NAME + "="
+ name +"'", null, null, null, null);
if (c != null) {
c.moveToFirst();
return namereturned = c.getString(1);
}
return null;
}
LOG CAT
10-04 15:15:05.954: E/AndroidRuntime(760): FATAL EXCEPTION: main
10-04 15:15:05.954: E/AndroidRuntime(760): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.contactlist/com.example.contactlist.ViewContact}: android.database.sqlite.SQLiteException: unrecognized token: "'" (code 1): , while compiling: SELECT _id, Name, Personalnumber, Homenumber, Officenumber FROM ContactList WHERE Name=nishanth'
10-04 15:15:05.954: E/AndroidRuntime(760): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.os.Handler.dispatchMessage(Handler.java:99)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.os.Looper.loop(Looper.java:137)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.app.ActivityThread.main(ActivityThread.java:4745)
10-04 15:15:05.954: E/AndroidRuntime(760): at java.lang.reflect.Method.invokeNative(Native Method)
10-04 15:15:05.954: E/AndroidRuntime(760): at java.lang.reflect.Method.invoke(Method.java:511)
10-04 15:15:05.954: E/AndroidRuntime(760): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-04 15:15:05.954: E/AndroidRuntime(760): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-04 15:15:05.954: E/AndroidRuntime(760): at dalvik.system.NativeStart.main(Native Method)
10-04 15:15:05.954: E/AndroidRuntime(760): Caused by: android.database.sqlite.SQLiteException: unrecognized token: "'" (code 1): , while compiling: SELECT _id, Name, Personalnumber, Homenumber, Officenumber FROM ContactList WHERE Name=nishanth'
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
10-04 15:15:05.954: E/AndroidRuntime(760): at com.example.contactlist.DBContact.getName(DBContact.java:138)
10-04 15:15:05.954: E/AndroidRuntime(760): at com.example.contactlist.ViewContact.onCreate(ViewContact.java:31)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.app.Activity.performCreate(Activity.java:5008)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-04 15:15:05.954: E/AndroidRuntime(760): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
10-04 15:15:05.954: E/AndroidRuntime(760): ... 11 more