之前学的都是android stdio中的部件的用法和属性,今天完成了数据库的连接,以及如何使用navite可视化工具,可视android stdio中所创建的数据库。
package com.example.ditiexianlu2; import androidx.appcompat.app.AppCompatActivity; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import DButil.util; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); util ut=new util(MainActivity.this,"ditiexianlu.db",null,1); SQLiteDatabase db=ut.getWritableDatabase(); db.close(); } }
package DButil; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import androidx.annotation.Nullable; public class util extends SQLiteOpenHelper { public util(@Nullable Context context, String database, SQLiteDatabase.CursorFactory fc, int version) { super(context,database,fc,version); } @Override public void onCreate(SQLiteDatabase db) { String sql="create table firstline (StopID varchar(200),StopName varchar(255),Line varchar(255))"; String sql2="create table changestop (ID1 varchar(200),ID2 varchar(255),ChangeStopName varchar(255))"; db.execSQL(sql); db.execSQL(sql2); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }
标签:util,varchar,SQLiteDatabase,db,二十五日,三月,import,android From: https://www.cnblogs.com/mine-my/p/17255664.html