gpt4 book ai didi

java - SQLite 文件打开器 Android Studio

转载 作者:太空宇宙 更新时间:2023-11-04 09:15:04 24 4
gpt4 key购买 nike

我刚刚启动了一个 Android studio 项目,我编写了一些代码来在 SQLite 中创建一个表。

数据库没有简单的用户界面,因此我尝试安装插件 DB Navigator。这需要我将导航器链接到我的数据库,但无法找到将创建文件的位置。

很多答案都被认为是去/data/data/,但我在我的目录中找不到这些文件夹。

知道如何精确定位我的 SQLite 数据库吗?任何帮助是极大的赞赏。

SQLiteController.java

  package com.example.apexstrength;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import static java.sql.Types.NULL;

public class SQLiteController extends SQLiteOpenHelper { //abstract to prevent creating/dropping tables

private static final int DATABASE_VERSION=1;
private static final String DATABASE_NAME="ApexStrength";
private static final String TABLE_USER="user";

private static final String KEY_userName="userName",KEY_password="password", KEY_firstName="firstName",KEY_surname="surname", KEY_EMAIL="email";

public SQLiteController(Context context)
{
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}

public void addUser( String userName, String password, String firstName, String surname, String email)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_userName, userName);
values.put(KEY_password, password);
values.put(KEY_firstName, firstName);
values.put(KEY_surname, surname);
values.put(KEY_EMAIL, email);


//inserting rows
db.insert(TABLE_USER, null, values);
db.close();
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE IF NOT EXISTS user (username VARCHAR, password VARCHAR, firstName VARCHAR, surname VARCHAR, email VARCHAR)"); //Create table is not there.
// db.execSQL("CREATE TABLE IF NOT EXISTS exercise (username VARCHAR, password VARCHAR, firstName VARCHAR, surname VARCHAR, email VARCHAR)");
// db.execSQL("CREATE TABLE IF NOT EXISTS workout (username VARCHAR, password VARCHAR, firstName VARCHAR, surname VARCHAR, email VARCHAR)");
// db.execSQL("CREATE TABLE IF NOT EXISTS sets (username VARCHAR, password VARCHAR, firstName VARCHAR, surname VARCHAR, email VARCHAR)");
}

public boolean logIn(String username, String password) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery("select * from user where username=? and password=?", new String[]{username,password});
if(c.getCount()>0)
{
return true;
}
return false;
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}

signUp.java

package com.example.apexstrength;

import androidx.appcompat.app.AppCompatActivity;

import android.app.DownloadManager;
import android.content.Intent;
import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class signUp extends AppCompatActivity {
private SQLiteController db;

public void register(View view) {
EditText user = (EditText) findViewById(R.id.passwordReg);
EditText pass = (EditText) findViewById(R.id.userReg);
EditText first = (EditText) findViewById(R.id.firstNameReg);
EditText sur = (EditText) findViewById(R.id.surnameReg);
EditText email = (EditText) findViewById(R.id.emailReg);

String username = user.getText().toString();
String password = pass.getText().toString();
String firstname = first.getText().toString();
String surname = sur.getText().toString();
String emailAddress = email.getText().toString();

if (!username.isEmpty() && !password.isEmpty() && !firstname.isEmpty() && !surname.isEmpty() && !emailAddress.isEmpty()) {
db.addUser(username, password, firstname, surname, emailAddress);
Toast.makeText(getApplicationContext(), emailAddress+ " has been registered!", Toast.LENGTH_LONG).show();
Intent i = new Intent(getApplicationContext(), MainActivity.class);
startActivity(i);
} else {
Toast.makeText(getApplicationContext(), "Please enter your details", Toast.LENGTH_LONG).show();
}
}

public boolean onCreateOptionsMenu(Menu menu) //Creating options menu
{
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.main_menu, menu);

return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);

switch (item.getItemId()) {
//Selected items, log selected
case R.id.home:
Log.i("Menu item selected", "Home");
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
return true;
case R.id.settings:
Log.i("Menu item selected", "Settings");
return true;
case R.id.help:
Log.i("Menu item selected", "Help");
return true;
case R.id.weightConversion:
Log.i("Menu item selected", "Weight Conversion");
intent = new Intent(this, weightConversion.class);
startActivity(intent);
return true;
default:
return false;

}
}



@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
db= new SQLiteController(getApplicationContext());
}}

最佳答案

在 Android 中,您可以使用设备资源管理器(默认在右下角或通过 View /工具窗口/设备资源管理器)

enter image description here

然后是类似以下内容:-

enter image description here

然后您可以右键单击数据库并使用另存为复制路径

  • 请注意,如果存在 -wal 文件且不为空,则应将 -wal 和 -shm 文件与数据库文件一起复制。

关于java - SQLite 文件打开器 Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59139874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com