parent
05df22e3f4
commit
ceabe72e56
@ -0,0 +1 @@
|
||||
<root></root>
|
@ -0,0 +1,4 @@
|
||||
package com.example.test1.Activity;
|
||||
|
||||
public class IndexActivity {
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package com.example.test1;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
|
||||
public class Database extends SQLiteOpenHelper {
|
||||
public Database(@Nullable Context context) {
|
||||
|
||||
super(context, "orange", null, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
//创建用户表
|
||||
String sql = "create table good_user(id integer primary key autoincrement, username varchar(50), password varchar(50),sex varchar(10),city carchar(50))";
|
||||
db.execSQL(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
|
||||
//插入数据
|
||||
public void insertUser(SQLiteDatabase sqLiteDatabase, String username, String password, String sex, String city) {
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("username", username);
|
||||
contentValues.put("password", password);
|
||||
contentValues.put("sex", sex);
|
||||
contentValues.put("city", city);
|
||||
sqLiteDatabase.insert("good_user", null, contentValues);
|
||||
sqLiteDatabase.close();
|
||||
}
|
||||
|
||||
//查询数据
|
||||
public static Bundle queryUserInfo(SQLiteDatabase sqLiteDatabase, Bundle bundle) {
|
||||
String username = bundle.getString("username");
|
||||
Cursor cursor = sqLiteDatabase.rawQuery("select * from good_user where username=?", new String[]{username});
|
||||
if (cursor != null) {
|
||||
while (cursor.moveToNext()) {
|
||||
bundle.putString("sex", cursor.getString(3));
|
||||
bundle.putString("city", cursor.getString(4));
|
||||
}
|
||||
}
|
||||
cursor.close();
|
||||
sqLiteDatabase.close();
|
||||
return bundle;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue