12-24 18:24:36.679: E/SQLiteLog(908): (1) near "Rallis": syntax error
12-24 18:24:36.679: E/SQLiteDatabase(908): Error inserting Tata Rallis=Distributor Syngenta=Retailer Naziveedu=Distributor UPL=Retailer Bayer=Dealer Pioneer=Retailer Razi=Retailer Monsanto=Distributor BASF=Distributor DuPont=Distributor Nagarjuna=Retailer Rallies=Distributor Gharda=Distributor Mahyco=Retailer Cheminova=Dealer Id=null Ankur =Dealer Excel=Dealer
12-24 18:24:36.679: E/SQLiteDatabase(908): android.database.sqlite.SQLiteException: near "Rallis": syntax error (code 1): , while compiling: INSERT INTO Partners(Tata Rallis,Syngenta,Naziveedu,UPL,Bayer,Pioneer,Razi,Monsanto,BASF,DuPont,Nagarjuna,Rallies,Gharda,Mahyco,Cheminova,Id,Ankur ,Excel) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
12-24 18:24:36.679: E/SQLiteDatabase(908): at com.activeandroid.Model.save(Model.java:153)
12-24 18:24:36.679: E/SQLiteDatabase(908): at com.softsol.survey_app.Submit$2.onClick(Submit.java:86)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.view.View.performClick(View.java:4084)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.view.View$PerformClick.run(View.java:16966)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.os.Handler.handleCallback(Handler.java:615)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.os.Handler.dispatchMessage(Handler.java:92)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.os.Looper.loop(Looper.java:137)
12-24 18:24:36.679: E/SQLiteDatabase(908): at android.app.ActivityThread.main(ActivityThread.java:4745)
12-24 18:24:36.679: E/SQLiteDatabase(908): at java.lang.reflect.Method.invokeNative(Native Method)
12-24 18:24:36.679: E/SQLiteDatabase(908): at java.lang.reflect.Method.invoke(Method.java:511)
12-24 18:24:36.679: E/SQLiteDatabase(908): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
12-24 18:24:36.679: E/SQLiteDatabase(908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12-24 18:24:36.679: E/SQLiteDatabase(908): at dalvik.system.NativeStart.main(Native Method)
当我尝试将数据输入数据库时,我收到此错误。 以下是扩展模型的类(我使用activeandroid) 两个表MajorPartners和TechDetails链接到主表Person。 这是MajorPartners表
@Table(name = "Partners")
public class MajorPartners extends Model {
@Column(name = "Bayer")
public String bayer;
@Column(name = "DuPont")
public String duPont;
@Column(name = "BASF")
public String basf;
@Column(name = "Monsanto")
public String monsanto;
@Column(name = "Tata Rallis")
public String tataRallis;
@Column(name = "Cheminova")
public String cheminova;
@Column(name = "Syngenta")
public String syngenta;
@Column(name = "UPL")
public String upl;
@Column(name = "Nagarjuna")
public String nagarjuna;
@Column(name = "Pioneer")
public String pioneer;
@Column(name = "Rallies")
public String rallies;
@Column(name = "Excel")
public String excel;
@Column(name = "Gharda")
public String gharda;
@Column(name = "Razi")
public String razi;
@Column(name = "Naziveedu")
public String naziveedu;
@Column(name = "Ankur ")
public String ankur;
@Column(name = "Mahyco")
public String mahyco;
public MajorPartners()
{
super();
}
public MajorPartners(String[] values)
{
super();
this.bayer = values[0];
this.duPont = values[1];
this.basf = values[2];
this.monsanto = values[3];
this.tataRallis = values[4];
this.cheminova = values[5];
this.syngenta = values[6];
this.upl = values[7];
this.nagarjuna = values[8];
this.pioneer = values[9];
this.rallies = values[10];
this.excel = values[11];
this.gharda = values[12];
this.razi = values[13];
this.naziveedu = values[14];
this.ankur = values[15];
this.mahyco = values[16];
}
}
这是TechDetails表
@Table(name = "TechnicalDetails")
public class TechnicalDetails extends Model {
@Column(name = "storeArea")
public String storeArea;
@Column(name = "numberOfSalesPerson")
public String numberOfSalesPerson;
@Column(name = "totalRevenue")
public String totalRevenue;
@Column(name = "numberOfFarmersServing")
public String numberOfFarmersServing;
@Column(name = "catchmentArea")
public String catchmentArea;
@Column(name = "farmerOrientedService")
public String farmerOrientedService;
public TechnicalDetails()
{
super();
}
public TechnicalDetails(String storeArea,String numberOfSalesPerson,String totalRevenue,
String numberOfFarmersServing, String catchmentArea,String farmerOrientedService )
{
super();
this.storeArea = storeArea;
this.numberOfSalesPerson = numberOfSalesPerson;
this.totalRevenue = totalRevenue;
this.numberOfFarmersServing = numberOfFarmersServing;
this.catchmentArea = catchmentArea;
this.farmerOrientedService = farmerOrientedService;
}
}
这是人员表
@Table(name = "Person")
public class Person extends Model {
@Column(name = "personName")
public String personName;
@Column(name = "address")
public String address;
@Column(name = "district")
public String district;
@Column(name = "block")
public String block;
@Column(name = "MajorPartnersId")
public MajorPartners majorPartnerId;
@Column(name = "TechnicalDetailsId")
public TechnicalDetails technicalDetailsId;
public Person()
{
super();
}
public Person(String personName ,String address , String district, String block, MajorPartners majorPartnersId, TechnicalDetails technicalDetailsId)
{
super();
this.personName = personName;
this.address = address;
this.district = district;
this.block = block;
this.majorPartnerId = majorPartnersId;
this.technicalDetailsId = technicalDetailsId;
}
}
这是我将信息输入数据库的方式。
public class Submit extends Activity {
Button sub;
Button exi;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
setContentView(R.layout.submit_screen);
sub=(Button)findViewById(R.id.sub_but);
exi=(Button)findViewById(R.id.exi_but);
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String yesNo;
if(Tech.flag==1){ yesNo="YES";}
else{yesNo="NO";}
TechnicalDetails technicalDetails = new TechnicalDetails(
Tech.store_area.getText().toString(),
Tech.no_of_sales.getText().toString(),
Tech.total_rev.getText().toString(),
Tech.no_of_farm.getText().toString(),
Tech.catch_area.getText().toString(),
yesNo);
technicalDetails.save();
MajorPartners majorPartners = new MajorPartners(Part0.value);
majorPartners.save();
Person person = new Person(Registration.name.getText().toString(), Registration.address.getText().toString(),
Registration.district.getText().toString(), Registration.block.getText().toString(),
majorPartners, technicalDetails);
person.save();
Intent intent = new Intent(getApplicationContext(), Start.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
}
});
exi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String yesNo;
if(Tech.flag==1){ yesNo="YES";}
else{yesNo="NO";}
TechnicalDetails technicalDetails = new TechnicalDetails(
Tech.store_area.getText().toString(),
Tech.no_of_sales.getText().toString(),
Tech.total_rev.getText().toString(),
Tech.no_of_farm.getText().toString(),
Tech.catch_area.getText().toString(),
yesNo);
technicalDetails.save();
MajorPartners majorPartners = new MajorPartners(Part0.value);
majorPartners.save();
Person person = new Person(Registration.name.getText().toString(), Registration.address.getText().toString(),
Registration.district.getText().toString(), Registration.block.getText().toString(),
majorPartners, technicalDetails);
person.save();
Intent intent = new Intent(getApplicationContext(), Start.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("SHUT", true);
startActivity(intent);
}
});
}
}
答案 0 :(得分:0)
从列名Tata Rallis
中删除空格。