I am developing a private web application in Java with a mySQL database. I am having one problem and a question.
As IDE I am using IntelliJ. Now I am at a point where I have to implement a way to insert a lot of data behind each other, but that takes a lot of time. Therefore I thought of prepping a csv file, temporally store it in the project folder and bulk insert it in the DB.
I've found the option LOAD DATA INFILE '/path/to/products.csv' INTO TABLE products;
And for the path I've used
URL url = ClassLoader.class.getResource("sample.csv");
String path = url.getPath();
But the url is always null, even though the class and the csv are in the same folder. What am I doing wrong?
Since I can't get to the next step I wasn't able to test the LOAD DATA way. Is my way possible at all? Or do you have a better suggestion to me.
Thank you for your time!
Related
I have created a java web application in netbeans for a college project. I have read that saving images to a folder is more efficient than using BLOB files. However, I am finding it difficult to find a simple example that works online. Would someone please be able to send me in the right direction :)
New a map of picId/picPath, use java.io upload to setr, then insert the path.
I read couple of topics but didn't find a good answer.
I used netBeans IDE and created a program (using GUI)
and using a derby database (threw the netBeans IDE)
and now when I'm finished I want to create one single file that I can send to my friends that contains the app and also the database.
if there an option like this (like creating a runnable jar file + database included).
if not, is there a free-web-hosting to upload my database in?
if there is, please add a tutorial that explains how to do it.
and how to use this databse in my program (what url to get the Connection)
(the database is not big, only 3 tables with some lines in them).
*all of the url-paths I used are project-based (in the project folder - the databse url, files url and so...)
Thank you in advance, sorry for the English mistakes.
I am newbie in hsqldb.
In the project I am using Spring 4, Hibernate 5 and HSQLDB.
I am having some specific task and I am trying to use HSQLDB as a portable database, which can be transferred to a flash drive or another computer.
I already have an sql-script with all tables and basic-needed data.
I have four questions that are haunting me.
(I'm sorry in advance if these questions are very stupid):
I need to make the script run at the first launch of the program, and in the other launсhes it must to check if database already exist and (if it already exists)only update data in it. (the program would be used in many computers and the database must be created after the first launch).
How can I do this? Is it possible? Can you give some basic advice or example about how I can to do that?
I am trying to find some information about saving all database info in some file in the file-system. Can you give me please some valid examples about saving hsqldb data in file and about using this file after another launch.
Can I place this file in my project.jar file and to work with all data from it update it e.t.c. ?
What is the best practice to make my database portable(for specific tasks) and where should I keep it? In file, in my project jar.e.t.c.?
Thanks in advance for your answers!
For data storage, you use a file: database. The JDBC connection URL is in the form jdbc:hsqldb:file:<file path>. HSQLDB will save all the data to file.
After connecting to the database you execute the SQL statements in your script one by one. If the tables already exist, the CREATE TABLE statements throw an error. This shows you don't have to execute them.
Because it's up to you when to keep the existing data and when to update it based on the existing contents of the database, you execute some SQL statements to decide. There is no automatic way to do this.
You can put an HSQLDB database in a jar but it cannot be updated. Jars are read-only.
The databases are fully portable. You can place them in a subdirectory of the user's home directory with the ~ symbol. See http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html#dpc_variables_url and the rest of this page for details.
This may be a dumb question, but I have a project for a class where I have to store/retrieve files from a SQL database that connects to a web page. Now, I could just make a webpage to store pictures or music files but I am currently working on creating some basic games in java. I know that there are ways to be able to access these files from a web page, but like I said, the project has to include a SQL database.
So my question is, is there any way to store and retrieve these kinds of files from the SQL database? Being able to download the files would be fine as long as the user would be able to open them, though I would prefer the user be able to open them in the browser.
If anybody has any suggestions I would appreciate it.
When storing into a SQL database, you don't really store the files. You store the file contents. In it's most generic form, you could make a table with a big binary field (a blob or clob depending on which database you use) or a big text field (a varchar) and put the contents of the file into that. Other columns could store file names and such.
To really leverage the SQL database, you would want to know enough about the content of the files to take advantage of indexing and such by breaking it up into more detailed parts. For example, if you are putting a save file in there, you could make a detailed table with columns for username, and all sorts of game-specific state that needs to be saved.
I have created a Java desktop application which reads and should write to a Microsoft Access DB.
The application works fine before I convert it to a .JAR after which it can only read from the DB but doesn't write to it.
Any ideas on how to solve this issue?
I am guessing you've included the database file in the JAR file itself. Simply put, although you can get a URL to read a file from inside a JAR, you can't write to one. You're going to need to take the database (MDB file?) out of the JAR and put it in on the actual filesystem if you want to write to it.