Creating Database in JDBC Sqlite - java

I am using the SQLite driver from
http://code.google.com/p/sqlite-jdbc/wiki/Introduction
Examples shown in the above doc shows how to connect an existing database.
In my application I need to create an SQLite database. How to do that? Is it sufficient to create a file with extension .db?
Also is there a function called createFile(). If so how to use it? I googled and nobody is giving a clear answer.

SQLite creates new database file on first attempt to connect if file did not exist already.
So, simply use jdbc:sqlite:filename.db as JDBC connection string, and provided that you have permission to create filename.db, it will be created automatically. You can also manually pre-create this file with 0 size if you want.

Related

Android Room database created 3 files including -shm and -wal files

I have created a database using Room database library with name ImageDatabase, when I opened my Device File explorer in Android studio inside the database folder there were three files with names ImageDatabase, ImageDatabase-shm and ImageDatabase-wal. I wanted to know what are these files meant for? Any help would be great
Thanx All
The data in your database is contained in all three. The one with no extension is the main database. The others are the Write Ahead Log file (-wal) and the Shared Memory file (-shm). They are used by the underlying SQLite system to improve performance, and contain the latest changes to the main database until a checkpoint is done. You can find more information in the SQLite docs.
Your original database is ImageDatabase i.e name of database you give at the time of creation.
you can copy database and check the contain from here
upload your database in above link and you can verify it.

Accessing Connected Database DB in Eclipse with Java Code

I successfully connected to a DB in eclipse through the Database Development perspective and am able to run queries in the SQL File Editor. However, I would like to write java code to automatically run a query and then extract the data to a flat file. What is the easiest way to do this? Since I am already connected to the database, can I bypass the java code that involves connecting to the database.
No, the Java JVM also needs to be able to connect to the database. There are many examples of JDBC connections on the internet, including this one.
Once you have got the data you needed, you should make use of FileWriter in order to write the information to file.

Setting up sqlite database

Sorry I am a noob, I am trying to learn about sqlite databases using linux, I cannot find any tutorial that covers what I need from setup to creating to using. At the moment tutorials I find say open a shell using adb shell command but when I open a terminal this does not work even if I navigate to the android tools folder, I can get the sqlite command working but the tutorials dont explain how I use it. For instance, how do I store urls and map coordinates and how to I reference them.
I have tried to use the firefox plugin but I havent got a clue what it all means and every tutorial says sqlite database is easy but it seems so complicated.......HELP!!!!
P.S would it be possible to create the data within the application code, I have seen some apps that do this
Does anyone have a set up guide and tutorial that can help?
Take a look here: http://developer.android.com/guide/topics/data/data-storage.html#db
You should use a custom class extending SQLiteOpenHelper: http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
It gives you methods like onCreate, onOpen and onUpgrade which are very useful.
To set up your database :
The recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database.
To use it :
You can execute SQLite queries using the SQLiteDatabase query() methods, which accept various query parameters, such as the table to query, the projection, selection, columns, grouping, and others. For complex queries, such as those that require column aliases, you should use SQLiteQueryBuilder, which provides several convienent methods for building queries.
Resources :
developer.android.com - Data Storage
Are you using Java.
You can have a look http://www.zentus.com/sqlitejdbc/
Android has a class named SqliteOpenHelper using which you can create and communicate(do read / write operations) on sqlite using java. You can find many samples once you start searching in net. Here is one such sample.
http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
If you want to open your database you can use Sqlite Manager which is available with Firefox as a Addon. It has a easy interface so that you can load your database directly and check .
If you are planning to create a new SQLite database then over ride and implement the onCreate() Method.
But if you are using a SQLite database that is created by another external source and you are going to pull it down, then leave the onCreate() method empty.
You might look at SQLite Manager, which is a free GUI and available in a Linux variety. I highly recommend it.

HSQLDB - hiding database structure/contents from users

I'm considering using HSQLDB version 1.8.x in a desktop app for storing local data. From what I can see, the database is stored on disk as a number of SQL statements to create the tables, insert the data, etc.
Is there a simple way I can hide this from users? I'm don't necessarily need it to be completely encrypted, etc - I'd just like to prevent the casual user from simply opening the file and seeing the structure of the database.
You could embed your database files within a jar file and connect to them using the notation:
jdbc:hsqldb:res:<path in jar>
Check out the Advanced Topics section of the HSQLDB guide for more information on this. However, I've never tried it so am not 100% sure it will work ...
The solution I've gone with for now is to call:
db.update("SET SCRIPTFORMAT COMPRESSED;");
to store the .script file in a human-unreadable form and:
db.update("SET PASSWORD password;");
to prevent more savvy users from opening the DB using their own HSQLDB client.
Unfortunately I was not able to execute below command
db.update("SET scriptformat COMPRESSED");
And was getting this error
java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: SCRIPTFORMAT
This error solved with this command
db.update("SET FILES SCRIPT FORMAT COMPRESSED");
I am using HSQLDB 2.3.3

Read Firefox 3 bookmarks

Firefox 3 stores the bookmarks in a sqlite database.
There are several hacked sqlite java libraries available.
Is there a way to hack the sqlite database in java(not using libraries) to read bookmarks reliably?
Does someone know how the sqlite DB is stored and access programmatically (from java)?
You need the SQLite JDBC driver (this page explains how to run queries on a SQLite database using that driver from within Java).
I don't know why you need NOT to use a JDBC driver, but there's another possible "solution" depending on your software requirements. In FF3, type in the address bar about:config
Alter the value of property: browser.bookmarks.autoExportHTML to true.
This will export your bookmarks in an HTML whenever you close FF. You can then read the HTML. It may or may not solve your problem....

Categories

Resources