如何在android中获取sqlite数据库?

时间:2015-03-16 07:07:54

标签: android sql sqlite insert

在这段代码中我必须将sqlite数据插入到SQL server.First我必须将所有数据存储在sqlite数据库中,然后单击一个按钮,整个数据应插入SQL server.My问题是第一行只插入所有行。例如;如果我在Sqlite中插入三个不同的行,但这三行在Sql server中具有相同的第一行值.... 如何解决。我正在使用Move to first和Move to next ...但我无法得到。 伙计我需要你的帮助

//数据库编码

public class Database extends SQLiteOpenHelper {
    static int dbversion=1;
    static String dbname="auction.db";
    String TABLE_CONTACTS = "auctions";
    public Database(Context context)
             {
        super(context, dbname, null, dbversion);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("create table Auction(boname VARCHAR NOT NULL,bname VARCHAR NOT NULL, amount VARCHAR NOT NULL,daty DATE)");


}

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }
}

// JAva编码

public void onClick(View v) {
            // TODO Auto-generated method stub


            Database db=new Database(MainActivity.this);
            SQLiteDatabase sb=db.getReadableDatabase();


            Cursor cus=sb.rawQuery("select * from Auction",null);
            cus.moveToFirst();


             for(int i=0;i<cus.getCount();i++)
             {


             String Boatnum= cus.getString(0).toString();
             String Buyername=cus.getString(1).toString();

             String amount=     cus.getString(2).toString();




                        request.addProperty("Boatnum",Boatnum);
                        request.addProperty("Buyername",Buyername);
                        request.addProperty("amount",amount);


                                    envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
                                    envelope.dotNet=true;
                                    envelope.setOutputSoapObject(request);

                                    httpTransport = new HttpTransportSE(SOAP_ADDRESS);





                                    try {

                                         serviceCall();



                                    } 


                                    catch (Exception exception) {


                                        //Toast.makeText(getActivity(), "Registered Successfully", Toast.LENGTH_LONG).show();



              }
                                cus.moveToNext(); 


             }              


         }

1 个答案:

答案 0 :(得分:0)

您能否评论一下您现有的代码并尝试以下代码:

Cursor cus=sb.rawQuery("select * from Auction",null);
            if (cus != null) { 
            cus.moveToFirst();
    }

评论每一件事,只在你的方法中有这些并试着让我知道会发生什么。