I have a java web app. I need to point to an existing sqlite database that I have in the project root (in eclipse).
I have all of the required drivers/jars.
The problem is that code to select from my sqlite database tables runs against a newly created database. I get an error that my table "Table1" doesn't exist. I believe this is because a new database is being created as opposed to using the existing sqlite database in the root with the tables and data that I need.
Does anyone know how I can force this local sqlite database to be used?
Per the SQLite docs, a new database will be created by default if it doesn't find an existing one -- so the most likely explanation is that the path in your connection string isn't pointing to your pre-existing database.
See the question here about relative paths in web apps: if your web-app is a servlet, use ServletContext.getResource to get the path to your database to use in the connection string. So, if your existing database is in /WEB-INF:
ServletContext.getResource("/WEB-INF/my.db");
Related
I am working on project where I need to load data from local mobile DB(SQLite) to UI in meanwhile load data from server and when data download is finished insert the data from server to the database and update UI. I searching for way to download data from server and instead of delete all data in database and insert the new valid data just find the changes and "update" database. Is there some correct way to do this. I am working with SQLite database on Android phone.
SQLite isn't an online database meant to be ran on a server.
There aren't any free SQL Server options that I know of, but the NoSQL options include Firebase Realtime Database, Firebase Cloud Firestore, Realm Platform, Couchbase Mobile, Parse Server, etc...
Each of the listed options allow you to listen only to changes in the data. SQLite does not provide this option itself.
I have an application that uses an Oracle database. It reads data out of the database using statements like:
SELECT * from schema.table WHERE ...
I would like to create a SQLite database with data I can use for regression-testing the application. It's simple enough to change the jdbc settings to get the application to connect to a different database, but the SQL statements need to be exactly the same.
I know when I run SQLite from the command line, I can attach a database using
attach database as
If I do that, then the same select statements that work in oracle to access a table in a different Oracle schema will work to access the data in a different SQLite database. But, since I'm connecting via JDBC, I don't have the option to run the "attach database" command.
Is there a way to configure SQLite such that it will accept requests like the above?
I tried
create table "schema.table" ...
That worked, but then I need to include the quotes in the select statement, which Oracle won't allow.
How could we convert SQLite database to a Realm database?
Is there any way to use pre-populated databases with Realm on Android?
Currently there is no way to automatically convert a SQLite database to a Realm database, you would have to manually read all data from the SQLite database and insert them into Realm.
An alternative could be the Realm browser that might make this easier, but it is currently available for MacOS X only. You can read more here: https://github.com/realm/realm-java/issues/435
For the second part: As Realm databases are just a single file so you can easily add a pre-populated realm database to you app and reference it with Realm.getInstance().
This is an answer to the second part of the question.
While shipping a prepopulated database in the assets folder of your app, analogous to the official Objective-C to bundle of Realm with your app, is still probably the fastest way to get a prepopulated Realm if you have a lot of data. But as of Realm Java 0.89 there is now an official way to prepopulate a Realm database on Android.
There is now a method that allows for specifying a transaction to be run when a Realm database is created for the first time. You should call this method, initialData(Realm.Transaction transaction), as part of setting up the RealmConfiguration Builder.
For example
RealmConfiguration config = new RealmConfiguration.Builder(context)
.name("myrealm.realm")
.initialData(new MyInitialDataRealmTransaction()),
.build();
I have a third party tool that I want to detect right away that the database is missing, instead of creating the empty database. I cannot change the tool itself, but only configure it. Not getting any error during database connection gives the application the false impression that the database is there, with all necessary tables. So the application will fail only when it does not find the tables.
I want an SQLException to be thrown as soon as the application tries to connect to a database that does not exist. For instance, if the connection URL is jdbc:h2:/x/y and the file /x/y.h2.db does not exist.
Is there a way, using the connection URL, to specify that the database should not be created? In other words, is there a way to tell the H2 driver to treat the absence of data files as an error that should be reported?
Is there anything like this? => jdbc:h2:/x/y?ifFileNotFoundThanThrowException=true
Append ;ifexists=true to the database URL. See also the documentation at Database URL Overview
Im looking to connect to a URL and download a file (.db) and if it is of a higher version then update the database on the app. e.g. currently using Database1.db and this online one is Database2.db. However I'm not really sure how to go about this. Im using sqlite.
Thanks
From server end:
Instead of uploading database from url you can post xml or json data
which will give details bout database version and sql query
From android program
connect to url get the data check for the version if version from url
is higher than that of existing one then execute the sql query that
you got to create database and take backup of your data
Scenario
Lets consider one scenario you have some data in a table named y in
old database. but the new database which you are downloading doesn't
have that y table but it has some new table then what do you want to
perform with that data. Do you want to discard or store if store and
use then to where you want to store.