- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在向数据库中插入数据时出错。
01-28 20:59:06.277: I/Database(553): sqlite returned: error code = 1, msg = table tableKo has no column named phone
01-28 20:59:06.309: E/Database(553): Error inserting phone= email= address= name=
01-28 20:59:06.309: E/Database(553): android.database.sqlite.SQLiteException: table tableKo has no column named phone: , while compiling: INSERT INTO tableKo(phone, email, address, name) VALUES(?, ?, ?, ?);
01-28 20:59:06.309: E/Database(553): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
01-28 20:59:06.309: E/Database(553): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
01-28 20:59:06.309: E/Database(553): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
01-28 20:59:06.309: E/Database(553): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
01-28 20:59:06.309: E/Database(553): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
01-28 20:59:06.309: E/Database(553): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
01-28 20:59:06.309: E/Database(553): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
01-28 20:59:06.309: E/Database(553): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
01-28 20:59:06.309: E/Database(553): at com.example.databasetest.DBHandler.insertData(DBHandler.java:76)
01-28 20:59:06.309: E/Database(553): at com.example.databasetest.MainActivity.saveButtonHandler(MainActivity.java:39)
01-28 20:59:06.309: E/Database(553): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 20:59:06.309: E/Database(553): at java.lang.reflect.Method.invoke(Method.java:521)
01-28 20:59:06.309: E/Database(553): at android.view.View$1.onClick(View.java:2067)
01-28 20:59:06.309: E/Database(553): at android.view.View.performClick(View.java:2408)
01-28 20:59:06.309: E/Database(553): at android.view.View$PerformClick.run(View.java:8816)
01-28 20:59:06.309: E/Database(553): at android.os.Handler.handleCallback(Handler.java:587)
01-28 20:59:06.309: E/Database(553): at android.os.Handler.dispatchMessage(Handler.java:92)
01-28 20:59:06.309: E/Database(553): at android.os.Looper.loop(Looper.java:123)
01-28 20:59:06.309: E/Database(553): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-28 20:59:06.309: E/Database(553): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 20:59:06.309: E/Database(553): at java.lang.reflect.Method.invoke(Method.java:521)
01-28 20:59:06.309: E/Database(553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-28 20:59:06.309: E/Database(553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-28 20:59:06.309: E/Database(553): at dalvik.system.NativeStart.main(Native Method)
我使用一个单独的类来扩展 SQLiteOpenHelper 来处理我的数据库。我已经在互联网上搜索以了解我的表怎么没有列名,这是我的代码:我的主课
package com.example.databasetest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText nameET;
EditText addressET;
EditText phoneET;
EditText emailET;
String name;
String address;
String phone;
String email;
DBHandler handler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nameET = (EditText)findViewById(R.id.nameET);
addressET = (EditText)findViewById(R.id.addressET);
phoneET = (EditText)findViewById(R.id.phoneET);
emailET = (EditText)findViewById(R.id.emailET);
name = nameET.getText().toString();
address = addressET.getText().toString();
phone = phoneET.getText().toString();
email = emailET.getText().toString();
handler = new DBHandler(this);
}
public void saveButtonHandler(View v) {
handler.insertData(name, address, phone, email);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
这是我的数据库处理程序类
package com.example.databasetest;
import android.content.ContentValues;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBHandler {
public static final String TABLE_NAME = "tableKo";
public static final String DATABASE_NAME = "databaseKo";
private static final int DATABASE_VERSION = 1;
private static final String TAG = "DBHandler";
public static final String COL_ID = "_id";
public static final String COL_NAME = "name";
public static final String COL_ADDRESS = "address";
public static final String COL_PHONE = "phone";
public static final String COL_EMAIL = "email";
private final Context context;
private SQLiteDatabase db;
private MySQLiteOpenHelper DBHelper;
private static final String CREATE_DATABASE ="create table "
+ TABLE_NAME + "(" + COL_ID
+ " integer primary key, " + COL_NAME
+ " text not null, " + COL_ADDRESS + "text not null,"
+ COL_PHONE + "text not null," + COL_EMAIL + "text not null);";
public DBHandler(Context ctx) {
this.context = ctx;
DBHelper = new MySQLiteOpenHelper(context);
}
private static class MySQLiteOpenHelper extends SQLiteOpenHelper{
public MySQLiteOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
try {
db.execSQL(CREATE_DATABASE);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(TAG, oldVersion + " to " + newVersion
+ ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
public DBHandler open() throws SQLException {
db = DBHelper.getWritableDatabase();
return this;
}
public void close() {
DBHelper.close();
}
public void insertData (String name, String address, String phone, String email) {
open();
ContentValues values = new ContentValues();
values.put(COL_NAME, name);
values.put(COL_ADDRESS, address);
values.put(COL_PHONE, phone);
values.put(COL_EMAIL, email);
db.insert(TABLE_NAME, null, values);
//db.execSQL("Insert into " +TABLE_NAME+ " VALUES('"+COL_ID+"','"+name+"','"+address+"','"+phone+"','"+email+"');");
db.close();
}
}
我的代码有什么问题?预先感谢您的帮助
最佳答案
你错过了一个空格:
代替
COL_PHONE + "text not null,"
使用
COL_PHONE + " text not null,"
关于android - "Table X has no column named Y"将数据插入 SQLite 数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14562789/
我刚刚编写了这些代码,但输出不同。第二个代码的输出符合我的预期,但第一个代码的输出不正确。但为什么呢? def fib(n): x = 0 y = 1 print x
#include #include #define CUBE(y)y*(y*y) main() { int j; j = CUBE(-2+4);
这个问题在这里已经有了答案: Multiple assignment and evaluation order in Python (11 个答案) 关闭 1 年前。 我看到下面的代码,但不知道它做
我正在阅读 book , 并讲了 typeclass Eq 的定义 有两个功能== , /=在等式中,它们被实现为: x == y = not (x /= y) x /= y = not (
我最近参加了一个代码力量竞赛。在比赛的编辑部分,我看到了按位运算符之间的一种美妙关系,即 x + y = x & y + x |是的我还不知道证据。我拿了几个数字来看看这个等式是否正确。我很高兴知道这
我使用 CGRectMake(x,x,x,x) 在我的 View 中放置了一个按钮,当然 x 是位置和大小。当我使用 -(BOOL)shouldAutoRotate... 旋转 View 时,我想将按
this.x = (Math.random()*canvasWidth); this.y = (Math.random()*canvasHeight); (1) this.shift = {x: th
我想将此代码运行为“if 'Britain' or 'UK' in string do stuff, but don't do stuff if "Ex UK" 在字符串中": #Case insen
早上好,我是新来的,我带来了一个小问题。我无法针对以下问题开发有效的算法:我需要找到三个正数 x、y 和 z 的组合,以便 x + y、x - y、y + z、y - z、x + z 和 x - z
我现在正在使用 C++ 编写方案的解释器。我有一个关于定义和 lambda 的问题。 (define (add x y) (+ x y)) 扩展为 (define add (lambda (x y)
我正在尝试使用一台主机通过 FTP 将内容上传到另一台主机。 “我不会打开到 172.xxx.xxx.xxx(仅到 54.xxx.xxx.xxx)的连接”甚至不相关,因为我没有连接到那个主持人。这是托
在 Python 中,使用 [] 解包函数调用有什么区别? , 与 ()还是一无所有? def f(): return 0, 1 a, b = f() # 1 [a, b] = f() # 2
给定方程 z = z(x,y) 2 个表面 I和 II : z_I(x, y) = a0 + a1*y + a2*x + a3*y**2 + a4*x**2 + a5*x*y z_II(x, y)
几年前我有这个面试问题,但我还没有找到答案。 x 和 y 应该是什么才能形成无限循环? while (x = y && x != y) { } 我们尝试了 Nan,infinity+/-,null f
我正在尝试使用 Camel FTP Producer 将文件发送到第三方 ftp 服务器(似乎由 Amazon 托管),但遇到了一个问题,写入文件失败,并显示:文件操作失败...主机尝试数据连接 x.
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
我正在使用 torch.tensor.repeat() x = torch.tensor([[1, 2, 3], [4, 5, 6]]) period = x.size(1) repeats = [1
#include int main() { int x = 9; int y = 2; int z = x - (x / y) * y; printf("%d", z
我很难理解先有定义然后有两个异或表达式的含义。这个定义的作用是什么? 我尝试发送 x=8, y=7,结果是 x=15 和 y=8为什么会这样? 这是程序: #define FUNC(a,b) a^=b
我正在尝试使用 SIMD 优化此功能,但我不知道从哪里开始。 long sum(int x,int y) { return x*x*x+y*y*y; } 反汇编函数如下所示: 4007a0
我是一名优秀的程序员,十分优秀!