结尾
这不止是一份面试清单,更是一种”被期望的责任“,因为有无数个待面试者,希望从这篇文章中,找出通往期望公司的”钥匙“,所以上面每道选题都是结合我自身的经验于千万个面试题中经过艰辛的两周,一个题一个题筛选出来再次对好答案和格式做出来的,面试的答案也是再三斟酌,深怕误人子弟是小,影响他人仕途才是大过,也希望您能把这篇文章分享给更多的朋友,让他帮助更多的人,帮助他人,快乐自己,最后,感谢您的阅读。
由于细节内容实在太多啦,在这里我花了两周的时间把这些答案整理成一份文档了,在这里只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!
case CATEGORY_DIR:
updatedRows = db.update(“Category”, values, selection, selectionArgs);
break;
case CATEGORY_ITEM:
String categoryId = uri.getPathSegments().get(1);
updatedRows = db.update(“Category”, values, “id = ?”, new String[] { categoryId });
break;
default:
break;
}
return updatedRows;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
// 删除数据
SQLiteDatabase db = dbHelper.getWritableDatabase();
int deletedRows = 0;
switch (uriMatcher.match(uri)) {
case BOOK_DIR:
deletedRows = db.delete(“Book”, selection, selectionArgs);
break;
case BOOK_ITEM:
String bookId = uri.getPathSegments().get(1);
deletedRows = db.delete(“Book”, “id = ?”, new String[] { bookId });
break;
case CATEGORY_DIR:
deletedRows = db.delete(“Category”, selection, selectionArgs);
break;
case CATEGORY_ITEM:
String categoryId = uri.getPathSegments().get(1);
deletedRows = db.delete(“Category”, “id = ?”, new String[] { categoryId });
break;
default:
break;
}
return deletedRows;
}
@Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri)) {
case BOOK_DIR:
return “vnd.android.cursor.dir/vnd.com.example.databasetest. provider.book”;
case BOOK_ITEM:
return “vnd.android.cursor.item/vnd.com.example.databasetest. provider.book”;
case CATEGORY_DIR:
return “vnd.android.cursor.dir/vnd.com.example.databasetest. provider.category”;
case CATEGORY_ITEM:
return “vnd.android.cursor.item/vnd.com.example.databasetest. provider.category”;
}
return null;
}
}
public class MyDatabaseHelper extends SQLiteOpenHelper {
public static final String CREATE_BOOK = “create table Book (”
-
"id integer primary key autoincrement, "
-
"author text, "
-
"price real, "
-
"pages integer, "
-
“name text)”;
public static final String CREATE_CATEGORY = “create table Category (”
-
"id integer primary key autoincrement, "
-
"category_name text, "
-
“category_code integer)”;
private Context mContext;
public MyDatabaseHelper(Context context, String name,
SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_BOOK);
db.execSQL(CREATE_CATEGORY);
// Toast.makeText(mContext, “Create succeeded”, Toast.LENGTH_SHORT).show();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(“drop table if exists Book”);
db.execSQL(“drop table if exists Category”);
onCreate(db);
}
}
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.example.databasetest”>
<application
android:allowBackup=“true”
android:icon=“@mipmap/ic_launcher”
android:label=“@string/app_name”
android:supportsRtl=“true”
android:theme=“@style/AppTheme”>
<provider
android:name=“.DatabaseProvider”
android:authorities=“com.example.databasetest.provider”
android:enabled=“true”
android:exported=“true” />
Provider项目,访问Database项目的数据
public class MainActivity extends AppCompatActivity {
private String newId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button addData = (Button) findViewById(R.id.add_data);
addData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 添加数据
Uri uri = Uri.parse(“content://com.example.databasetest.provider/book”);
ContentValues values = new ContentValues();
values.put(“name”, “A Clash of Kings”);
values.put(“author”, “George Martin”);
values.put(“pages”, 1040);
values.put(“price”, 55.55);
Uri newUri = getContentResolver().insert(uri, values);
newId = newUri.getPathSegments().get(1);
}
});
Button queryData = (Button) findViewById(R.id.query_data);
queryData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 查询数据
Uri uri = Uri.parse(“content://com.example.databasetest.provider/book”);
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
String name = cursor.getString(cursor. getColumnIndex(“name”));
String author = cursor.getString(cursor. getColumnIndex(“author”));
int pages = cursor.getInt(cursor.getColumnIndex (“pages”));
double price = cursor.getDouble(cursor. getColumnIndex(“price”));
Log.d(“MainActivity”, "book name is " + name);
Log.d(“MainActivity”, "book author is " + author);
Log.d(“MainActivity”, "book pages is " + pages);
Log.d(“MainActivity”, "book price is " + price);
}
cursor.close();
}
}
});
Button updateData = (Button) findViewById(R.id.update_data);
updateData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
总结
这个月马上就又要过去了,还在找工作的小伙伴要做好准备了,小编整理了大厂java程序员面试涉及到的绝大部分面试题及答案,希望能帮助到大家
这个月马上就又要过去了,还在找工作的小伙伴要做好准备了,小编整理了大厂java程序员面试涉及到的绝大部分面试题及答案,希望能帮助到大家
[外链图片转存中…(img-e2uDINhm-1715588068648)]
[外链图片转存中…(img-CR2Q64sj-1715588068648)]