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.
Related
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.
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.
Is there a way to perform SQL queries on CSV text held in memory and read in from a Java Reader e.g. StringReader.
org.h2.tools.Csv.read(Reader reader, String[] colNames) would allow me to retrieve a result set containing all the rows and columns. However, I actually want to perform a query on the CSV text read from the Reader.
The background - I receive a file containing multiple CSV sections for each entity, see Can H2 Database query a CSV file containing multiple sections of different record groups?, and whilst parsing the file I store each of the CSV sections I need in Strings (a String for each one). This shouldn't bog down memory as I only keep the data in memory for a short time and each CSV section is relatively small). I need to perform queries on these CSV sections to build a document in a custom format.
I could write each CSV section to a file (as a set of files) and use CSVREAD, but I don't want to do that as I need my application to be as fast as possible and splitting and writing the sections to disk will thrash the hard drive to death.
You could write a user defined function that returns a result set, and use that to generate the required rows. Within your user defined function, you can use the Csv tool from H2 (actually any Csv tool).
This is not possible directly, since DBMS can usually only query their own optimized data storage. You have to import the text with the mentioned org.h2.tools.Csv.read into a table and perform the queries on that table. The table may be a temporary one, to prevent any writes on the disk, assuming the memory is sufficient.
Hi I am new to mysql and java aswell. I want to store a jpeg files and hash values of small chunks of file. I have stored the hash values of small chunks(100s in number) and now want to store the jpeg file also against these small chunks. My question is do I need to store the file again and again for each record or is it possible to save file once and link it to the records related to the file? if so then also please guide me that how can I do it?
You can save the file on the machine and store its path in the database.
Suppose you are having 1 field (say imagePath) in the table which takes "varchar" data. You can store the path of the image there and retrieve the image at runtime. By doing this, you can avoid saving same file multiple times. However, it will override the images having same name but different data. For that you have to use Primary key to append to the name of the file. I hope it will help you to understand.
I must admit I'm not entirely sure what you want to do, but if understand you correctly this is what I would do.
One table (say tblJpgs) with data about the jpg-file, maybe the path and the filename as suggested by Naved and additionally a description and whatever can be useful info about the file. In this table there will be one row per jpg-file and each row will have a unique id.
Then you will have another table (say tblChunks) for all the chunks. There should be a column for connecting each row with a tblJpgs.id. Then there is of course a column with the chunk itself. In this table there will be one row for each chunk, but there will be many rows for one jpg-file.
In this way you will only save the information in one place, which is very central in database structures. Storing the jpg-file or the path and filename for it in each row with the chunks would be against this fundamental database structure and should therefore be avoided.
How do I write and read data in txt file in the form of rows and columns? Also, how do I store many files like this in a folder for a particular name? The idea is just like a Table for a particular person who has many rows and columns.
You'll want to look into comma-separated value files.
In addition to Jeremy's post
Use opencsv to create the csv file
Use CsvJdbc to use JDBC to query against those files. This makes the future transition to DB in future and you will be working with a known API for searching against the file