请看下面的代码
插入数据的代码
package com.example.esoftcallmanager;
import android.app.Activity;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;
public class DatabaseHandler implements DatabaseConnector
{
private SQLiteDatabase database;
private String dbPath = "data//data//com.example.esoftcallmanager.sqllite//esoftDatabase";
private static Context context;
private static DatabaseHandler instance;
private DatabaseHandler(Context context)
{
this.context = context;
}
@Override
public void createConnection()
{
try
{
database = context.openOrCreateDatabase("esoftDatabase", Context.MODE_PRIVATE, null);
String createDatabaseQuery = "create table BranchNetwork(" +
"brID integer primary key autoincrement,"
+"city text,"
+"streetAddress text,"
+"phoneNumber1 text,"
+"phoneNumber2 text,"
+"email text"
+");";
String dropDatabaseQuery = "drop table BranchNetwork";
database.execSQL(createDatabaseQuery);
}
catch(SQLException sql)
{
Toast.makeText(context, sql.getMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
public void closeConnection() {
// TODO Auto-generated method stub
}
@Override
public String getPhoneNumber() {
// TODO Auto-generated method stub
return null;
}
public static DatabaseHandler getInstance(Context context)
{
if(instance==null)
{
instance = new DatabaseHandler(context);
}
return instance;
}
public static DatabaseHandler getInstance()
{
if(instance==null)
{
instance = new DatabaseHandler(context);
}
return instance;
}
@Override
public String insertData(String city, String streetAddress,String phoneNumber1, String phoneNumber2, String email)
{
String insertQuery = "insert into BranchNetwork ('city','streetAddress','phoneNumber1','phoneNumber2','email') values("+city+","+streetAddress+","+phoneNumber1+","+phoneNumber2+","+email+");";
try
{
database.execSQL(insertQuery);
return "Data Successfully Inserted";
}
catch(Exception e)
{
Toast.makeText(context, "Exception: "+e.getMessage(), Toast.LENGTH_LONG).show();
return "Data Insertion Failed";
}
}
}
每当我尝试插入数据时,都会出现以下错误
02-13 23:39:40.424: E/Database(655): Failure 1 (near "@wewe": syntax error) on 0x2a6128 when preparing 'insert into BranchNetwork ('city','streetAddress','phoneNumber1','phoneNumber2','email') values(asas,asasd,3434,3434,aasa@wewe.com);'.
这里有什么问题?我该如何纠正?请帮忙!