SQLite语法错误代码(1)

时间:2014-10-20 11:59:56

标签: java android sqlite

我很长时间都面临着问题。

我在android SQLite数据库中动态生成插入查询,它会抛出以下错误。

     android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling: 
            INSERT INTO 'contacts' (id, name, phone_number, email, fax, job, company, website, address, 
            mobile) VALUES(98,'Vijay Bachani','022 - 61608080','','','TRAVEL CONSULTANT','RIYA TRAVEL &    
        TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001',''),
    (99,'Taha Udaipurwala','022 - 61608080','taha.udaipurwala@riya.travel','','JR. CONSULTANT','RIYA TRAVEL & TOURS 
    (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001',''),(100,'Salman Lakdawala','022 - 61608080','salman.lakdawala@riya.travel','','JUNIOR CONSULTANT','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001','9768683322'),(101,'Vipul Kharat','022 - 61608080','vipul.kharat@riya.travel','','JR. CONSULTANT','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001','9768215903'),(102,'Abdul Rafiq Siddique','022 - 61608080','rafiq.siddique@riya.travel','','JR. CONSULTANT','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001','9820327417'),(103,'Suryaji More','022 - 61608080','','','OFFICE ASSISTANT','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001',''),(104,'Wayne Joseph','022 - 61608080','','','SR. CONSULTANT','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001',''),(105,'GEORGE THOMAS','022 - 67772300','george.thomas@riya.travel','','GENERAL MANAGER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','M/1, Leela Business Park, Andheri Kurla road, Andheri (East), Mumbai - 400059','9820128819'),(106,'K P RAMKUMAR','022 - 67772300','ramkumar.menon@riya.travel','','MANAGER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','M/1, Leela Business Park, Andheri Kurla road, Andheri (East), Mumbai - 400059','9619481065'),(107,'SANDESH CHAVAN','022 - 29258611','sandesh.chavan@riya.travel','','ASST. MANAGER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','Atlanta Arcade, Ground Floor, Marol Church Road, Opp. The Leela, Andheri (E), Mumbai - 400 059','9619246722'),(108,'SUBRAMANIAN M S','022 - 61608080','subramanian.s@riya.travel','','ASST. MANAGER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001',''),(109,'JOVITA R. GONSALVES','022 - 29258611','jovita.gonsalves@riya.travel','','TEAM LEADER','RIYA TRAVEL & TOURS (I) 
PVT. LTD.','WWW.RIYA.TRAVEL','Atlanta Arcade, Ground Floor, Marol Church Road, Opp. The Leela, Andheri (E), Mumbai - 400 059','9881847272'),(110,'SALIM JAMADAR','022 - 
67772300','salim.jamadar@riya.travel','','SR. CONSULTANT','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','M/1, Leela Business Park, Andheri Kurla road, Andheri (East), Mumbai - 400059','9820593817'),(111,'ROHAN SURVE','022 - 67772300','rohan.surve@riya.travel','','ASST. MANAGER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','M/1, Leela Business Park, Andheri Kurla road, Andheri (East), Mumbai - 400059','8898211973'),(112,'NITHIN K','022 - 61608080','nithin.k@riya.travel','','ASST. MANAGER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001',''),(113,'MANOJ TAMBE','022 - 61608080','manoj.tambe@riya.travel','','SR. OFFICER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001',''),(114,'SUBASH N.L','022 - 29258611','subash.nl@riya.travel','','MANAGER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','Atlanta Arcade, Ground Floor, Marol Church Road, Opp. The Leela, Andheri (E), Mumbai - 400 059','9819517027'),(115,'DAVID M','022 - 29258611','david.m@riya.travel','','OFFICER','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','Atlanta Arcade, Grou

Java代码:

for (int i=0; i<flag; i++) {

                    JSONObject item = contactsdetails.getJSONObject(k);
                    int id = Integer.parseInt(item.getString("ID"));
                    String name = item.getString("Name");
                    String phone = item.getString("Telephone");
                    String email = item.getString("Email");
                    String fax = item.getString("Fax");
                    String company = item.getString("Company");
                    String address = item.getString("Address");
                    String  job= item.getString("Job");
                    String web = item.getString("Web");
                    String mobile = item.getString("Mobile"); 

                    //sqlString += "INSERT INTO '"+TABLE_CONTACTS+"' ("+KEY_ID+", "+KEY_NAME+", "+KEY_PH_NO+", "+KEY_EMAIL+", "+KEY_FAX+", "+KEY_JOB+", "+KEY_COMPANY+", "+KEY_WEBSITE+", "+KEY_ADDRESS+", "+KEY_MOBILE+") VALUES ("+id+",'"+name+"','"+phone+"','"+email+"','"+fax+"','"+job+"','"+company+"','"+web+"','"+address+"','"+mobile+"');";
                     sqlString += "("+id+",'"+name+"','"+phone+"','"+email+"','"+fax+"','"+job+"','"+company+"','"+web+"','"+address+"','"+mobile+"'),";
                     k++;
                }

真的很感激,如果有帮助

2 个答案:

答案 0 :(得分:1)

摆脱字符串连接。使用?作为位置占位符。这不仅可以处理您忽略的撇号和引号,还可以帮助您防御SQL注入攻击。

答案 1 :(得分:0)

您尝试使用一个INSERT插入多行。那是不可能做到的。每行需要一个INSERT

INSERT INTO 'contacts' (id, name, phone_number, email, fax, job, company, website, address,  mobile) VALUES (98,'Vijay Bachani','022 - 61608080','','','TRAVEL CONSULTANT','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001','')
INSERT INTO 'contacts' (id, name, phone_number, email, fax, job, company, website, address,  mobile) VALUES (99,'Taha Udaipurwala','022 - 61608080','taha.udaipurwala@riya.travel','','JR. CONSULTANT','RIYA TRAVEL & TOURS (I) PVT. LTD.','WWW.RIYA.TRAVEL','237 Gulab Building, P.D Mello Road, Mumbai, 400001','')

等等......这些INSERT中的每一个都需要逐个执行。