Android - SQLite Manager is hidden in eclipse - android

I am developing a simple database application.
I want to see the inserted data. I have follow this instructions to view the data.
But in eclipse the SQLite manage is hidden. Please let me any idea to show view the data.

Open view Window->Show View->File Explorer.
In this view go to data/data/"your app name"/databases/"your database" This is you database file.
For me, I use SQLite Database Browser.
Here, you can finf a good tutorial to know how to use it exactly.

Open the DDMS perspective and select the emulator, open the path: /data/data/your.app.name/databases/your.db and click the db file.
The icon will be then enabled
[UPDATE]
I noticed you are using ALL CAPS file names (...).
But I guess the plugin is case sensitive.
Try to make (at least) the extension SMALL CAPS: .db

Suppose If you have phone then you can copy the database to sdCard
private static String DB_NAME = "db_name";
private String DB_PATH = Environment.getDataDirectory().getAbsolutePath()
+ "/data/package_name/databases/";
private void copyToSdCard() throws IOException {
byte[] buffer = new byte[1024];
int length;
String outFileName = "/sdcard/file_name.sqlite";
OutputStream myOutput = new FileOutputStream(outFileName);
InputStream myInput;
myInput = new FileInputStream(DB_PATH + DB_NAME);
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myInput.close();
// Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
Then using mozila firefox add the add-on sqlitemanager and you can check your db. please replace the package name and db name.

Related

how to import database from downloads folder

public void copyDbToInternalFolder() throws IOException {
String DB_PATH = Environment.getDataDirectory().getPath()+getPackageName()+"/Databases/"; // Don't worry I know this line doesn't work, however, nothing was working
String DB_NAME = "Client_Responses.db";
InputStream myInput = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS,"Client_Responses.db"); //needs to get database file from Downloads folder
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
I have written several related apps that create sqlite database files in the devices Downloads folder. I need to stick to this method in order to support all the way back to first generation tablets. API 8 in essence.
Now, the manager needs to import found files from the Downloads folder and import them to its own database folder.
The above code doesn't work, null pointer exceptions and incorrect filename/pathname create errors and the app will force quit, and I have tried what seems like everything. My thinking is now bottlenecked.
I have been struggling with this and would welcome input.
Note: I will most likely duplicate the code in different class files, each copying a differing database name.
private void copyDbToInternalFolder() throws IOException {
String ToDB_PATH = "/data/data/"+this.getPackageName()+"/databases/";
String sourcePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/Client_Responses.db";
File source = new File(sourcePath);
String destinationPath = ToDB_PATH + "/" + DB_NAME;
File destination = new File(destinationPath);
try
{
FileUtils.copyFile(source, destination);
}
catch (IOException e)
{
e.printStackTrace();
}
}
This seems to work on Android4.2.2 tablet but not on the emulator. I cannot work out whether the issue is the emulator and how it handles the path creation, or if its API8 that cannot understand them. If anyone has any suggestions I would be grateful. So the issue is only partially answered.

Not able to access sqlite database Android

Ive created an app that stores user login information into an sqlite database. However when i try to access it using Root Explorer i get an error.
An error occurred while opening the database. disk i/o error (code 3850):, while compiling: Select * from sqlite_master where type in('table','view') order by name.
The app works fine, and it is storing the log in information as required. However i cant access it on the root explorer?
Any suggestions?
please call this function:
public static void copyDataBase(Context mActivity) throws IOException {
InputStream myInput = new FileInputStream(new File("/data/data/"
+ mActivity.getPackageName() + "/databases/" + "yourdb.sqlite"));
File files = new File("/sdcard/files/");
files.mkdirs();
String outFileName = "/sdcard/files/your.sqlite";
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int bufferLength;
while ((bufferLength = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, bufferLength);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
your database is copied /sdcard/files/your.sqlite this path.
You could add a button in your app to view the database information or write the database information to a file in external storage.
Otherwise, maybe you need to root your device to access the database.
Just give permissions to all users to the file [YOUR_DB].db-journal
For me it worked.

Android copy SQLite database from asset not work on KitKat 4.4

I red different question here on StackOverflow but mine is a little bit newer.
All of these don't work:
Question1
Question2
Question3
I updated my devices to Android KitKat 4.4 and when I try to copy database with this code:
private void copyDataBase() throws IOException {
InputStream myInput = context.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
I obtain a FileNotFoundException at line:
OutputStream myOutput = new FileOutputStream(outFileName);
Someone fix this issue on Android KitKat??? (other platforms works great)
Thanks for help.
Giulio
Full hardcoded
NEVER HARDCODE PATHS. Use getDatabasePath() to find the proper place for a database.
other platforms works great
It certainly will crash on Android 4.2+ tablets for secondary accounts. It may crash in other environments as well. NEVER HARDCODE PATHS.
Note that SQLiteAssetHelper uses getDatabasePath().

Saving sqlite data onto phone

I am currently trying to access my database using my android phone however it doesn't work. It does work on the emulator. So I was wondering if I need to copy the data into my phone's internal memory by using
try{
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}catch(SQLiteException e){
Another issue is that I did not use "SQLiteOpenHelper", so does the above method still work? I simply did a
private final String DB_NAME = "MemberData";
private final String TABLE_NAME = "MemberDB";
sampleDB = this.openOrCreateDatabase(DB_NAME, MODE_PRIVATE, null);
Cursor c = sampleDB.rawQuery("SELECT companyNameEng FROM " +
TABLE_NAME + " ORDER BY companyNameEng ASC", null);
Yes, you must copy the db file out of the apk and into your apps database directory (or somewhere else that your app can access). The assets directory is not really a directory when the .apk file is created... it's just data that certain functions in the framework (getAssets()) know how to access. To allow other functions that expect a real path to work, you need to copy the data out to a proper directory on the device.
The usual destination for a database is "data/data/your.package.name/databases/".
Your method looks like will work fine... it is standard java io. SQLiteOpenHelper is more for helping you do upgrades and create new dbs. I always use one (never know if I'm going to change how I do things even if I don't need it initially), but you certainly don't have to.

How to use existing/Predefined table in android?

Hi everyone i have one question i.e. i have some database table's which are already exist in database but i am not able to use them in my application. I am able to connect to database but i am not getting the tables which i have already created. I am not creating tables programmectically but i want to use existing table in my database. If i am creating tables programmetically then it's fine but how can i use existing table.
If anyone is having any idea plz suggest me some solution.
Answer to my question is simpelly copy your database by using the followig code.
private void CopyDataBase() throws IOException {
// open the local database
InputStream copy = context.getAssets().open(UR_DB_NAME);
// path where database is created
String path_DB = DB_PATH + DB_NAME;
// Open the empty dbOut as the output stream
OutputStream dbOut = new FileOutputStream(path_DB);
// copy database from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = copy.read(buffer)) > 0) {
dbOut.write(buffer, 0, length);
}
// Close the streams
dbOut.flush();
dbOut.close();
copy.close();
}

Categories

Resources