带有android的SQLiteException

时间:2012-08-24 06:18:42

标签: android sql sqlite

String insertQuery= "INSERT INTO"+ Table_Name +"(Coloum1, Coloum2, Coloum3, Coloum4,Coloum5,Coloum6,Coloum7,Coloum8,Coloum9) VALUES('fname','lname','dob','address','pin','city','tel','eid','date')" ;       
sd.execSQL(insertQuery);

我想通过此代码在sqlite db中编写,但它会引发异常:

08-24 09:51:53.858: E/(595): Exception   android.database.sqlite.SQLiteException: near "INTORegistrationTable11": syntax error: , while compiling: INSERT INTORegistrationTable11(Coloum1, Coloum2, Coloum3, Coloum4,Coloum5,Coloum6,Coloum7,Coloum8,Coloum9) VALUES('fname','lname','dob','address','pin','city','tel','eid','date')

3 个答案:

答案 0 :(得分:1)

看看它抱怨“INTORegistrationTable11”的SQL

看到缺少空间?

此:

String insertQuery= "INSERT INTO" + Table_Name + "(Coloum1, ...

应该是:

String insertQuery = "INSERT INTO " + Table_Name + " (Coloum1, ...

仔细阅读错误信息是软件工程的重要组成部分。

答案 1 :(得分:0)

String insertQuery= "INSERT INTO "+ Table_Name +" (Coloum1, Coloum2, Coloum3, Coloum4,Coloum5,Coloum6,Coloum7,Coloum8,Coloum9) VALUES('fname','lname','dob','address','pin','city','tel','eid','date')" ;

在INTO之后添加空格。

答案 2 :(得分:0)

空间,在为SQL编写这样的字符串时要非常小心,始终确保在每个SQL符号和单词之前和之后都有适当的空格。另外,为什么不使用内置的insert()函数并通过ContentValues提供数据?