SQLite open database from string - java

Assume I have a string containing an sqlite database.
(I read the entire content of the file containing the Sqlite database into a string)
Now, I want to get a connection to the database without saving the string to a file first.
Basically, this is an in-memory data base, which is totally possible in sqlite. But according to the sqlite documentation "[when you open an in memory data base] no disk file is opened. Instead, a new database is created purely in memory".
But I have string representing a data base. i want to use it and not create a new one.
Can this be done?

In-memory databases do not give you access to the underlying memory.
It is possible to copy databases with the backup API, but that would require another, file-based database.
Just create a temporary file, and open it directly.

Related

can i store text file in java derby database?

I want to store text files in java derby database and then from that data I want to plot some graph can I do that?(the text file contains ASCII data)
You can use one of these 3 methods to store the data
Store the contents of the file into a db column as text. Depending
upon the data size either CLOB or the VARCHAR variants can
be used.
Store the file as such into the database and use BINARY data
type. The file needs to be binary read and stored.
Instead of storing the file or its data into the database just save the file in a folder and insert the filename with path into the database. Then select the filename back from the database and read the contents directly from files the folder.
The graph can be plot according to your requirement and the type of graph directly using java code or a 3rd party library can also be used instead of reinventing the wheel.

How to save data in Java? Hotel Application

I am developing a small app for hotels. I am using java and mysql. I use mysql to save booking information and guest data and so on.
But now I want to make my program to be more flexible.
For example if I want to add more apartments(store apartment names) or change the payment methods. At this time I store the data as binary in files and read them from there when I start the program or when I need them.
Is this method correct? or is a better way? Should I use the mysql and read the data from there?
You should use a mySQL database. Store the data in tables with different columns based on the info. Use the tables to store the information so you don't need to convert it to binary.
To talk to the table, use the JDBC. There is a nice tutoral on using JDBC with mySQL. Refer to the SQL website on setting up tables on your mySQL database.

approach for storing image in sql database

i am trying to store image in sql on server. Later i want to make these image available for download. Which approach is good:
By uploading image and saving path.
or
2.By converting image to base64 and then storing as BLOB type
I'd say it's a tradeoff, and it also depends a lot on your network connection, I'd go for keeping the images in the cloud and just keeping a key in the database.
It would shrink the disk usage a lot , possibly even allowing the entire database to be cached into ram, thus balancing the extra time the process would spend retrieving the relevant info from the network
If the security is main concern then store image in DB in blob, or if if it is not much sensitive then store it in specific directory then store it's path in DB.
Because DB storage give it extra security.
If we store it on directory then someone can access it if they have tried some trick to access the directory.
So, and if we store it on directory then proper handling of file should be done.
Because if someone upload file then again other person store it wit same name then possibility of file overwrite.
So you can do something like that take 2 fields in table one is original name and one is new name that have original name plus the timestamp of file upload and in directory store it with that new name.
and if you are storing it in DB then doesn't need this extra work.
And yes bifurcation of images in directory also tough, suppose in one year so many file will be stored in it so indexing plus accessing become cumbersome work.
So apply some mechanism so at some time of interval you can separate images.

Store 200mb file in db2 database

I need to pick a file from a remote server of size 200mb and store it in db2 database (column as Blob type and corresponding Java type as byte[]).
Can anyone tell me what will be the good approach for this and how to go with that in Java?
Thanks all.
I amaze that why you want such a big file database. It dramatically reduce your database performance.
Although to do this use Binary / blob type data to store such a big file.
use these links for more details
http://www.ibm.com/developerworks/data/library/techarticle/0303stolze/0303stolze.html
http://www.dbforums.com/db2/1663961-insert-data-fields-clob-blob.html
Try it in some sandbox / virtual location.
BEWARE FOR DATA DAMAGE IN BIG FILE TRANSACTION OVER SLOW CONNECTION.

From a web app, I have to store a file in MS SQL 2008 DB. Do you recommend storing it as xml string or as a blob?

The web app has to let a user browse a csv file of around 100'000 lines.
We have to show the contents of the file on the screen so the user can see what has been loaded.
Then the user will perform some actions on the screen (e.g. add their details)
We need to store the file in database and associate it with the user record
The contents and the format of the file will change per user.
Therefore, I cannot create a static table in MS SQL DB for it.
Do you recommend loading this file as a blob in MS SQL 2008 DB or should I load the file, create a plain class (in C#) object that matches the file, serialise it and then store it as the xml file. Later if user wants to see it, I can read the xml string from DB, deserialise it to the object, write logic that takes the object and creates a csv file?
Is there another approach? Is storing as xml string better than storing as blob?
You could use the FILESTREAM data type in SQL Server 2008. Behind the scenes the actual file is stored on the file system but you get fully transactional access to it and the way it is actually stored is completely transparent.

Categories