【发布时间】:2016-01-22 15:43:49
【问题描述】:
我正在尝试在我的应用程序中执行一个简单的选择语句。我想要做的是返回一个与从列表视图接收的单词相关联的代码。当我运行代码时,我收到一条错误消息,指出该列不存在。它说不存在的列实际上是我传递给语句的变量,而不是表中的任何列。任何帮助都会很棒
SQL 语句
//gets recipe code given recipe name
public Cursor getCode(String name) throws SQLException
{
return db.rawQuery("select recipe_code from recipes where recipe_name = " + name ,null);
}
将变量传递给语句
TextView txtProduct = (TextView) findViewById(R.id.recipeTitle);
Intent i = getIntent();
// getting attached intent data
String string = i.getStringExtra("recipe");
// displaying selected product name
txtProduct.setText(string);
adapter.open();
Cursor code = adapter.getCode(string);
表创建
//Recipe create statement
private static final String CREATE_TABLE_RECIPES = "CREATE TABLE "
+ RECIPE_TABLE + "("
+ KEY_ID + " INTEGER AUTO INCREMENT,"
+ KEY_CODE + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ KEY_RECIPE_NAME + " TEXT" + ")";
【问题讨论】:
-
您在代码中的哪里创建表格?可以发一下吗?