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.
Related
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 currently developing an android app to download a file from server after which I need to delete it.
I've done a bit of Google and most of the solutions was to use the apache FTPClient. I personally prefer to use PHP to do the job but I have some concerns.
Can I and more importantly SHOULD I use PHP to delete said files? I would be passing the filename as POST data and not Query Strings. Will this be secure enough so people are unable to mess with my file system? Or will I need to watch out for other stuff
I am new to the php and i have not tried this but you should try this. Before downloading the file, get filename and store it in variable. Now after downloading file, search that file in the database and fire the query for deleting it.
I need to write a little Grails (or Java) app that will handle authentication (from our proprietary Single Sign On system) and then once authenticated allow a user to download files. This is very straight forward if I simply include the files in the WAR file of the application, however, I'd like to avoid that since there will be multiple files and I'd rather not have to upload a new WAR file every time we add a new file. Is it possible to accomplish this by having the application be in a WAR file but the files outside the WAR file, if so, how do I configure this kind of setup? We'll be running this on Tomcat.
Yes this is possible. Without knowing all your requirements or what you have tried and why it didn't work work for you the best I can do is give you a general idea of how to accomplish this.
Have a controller that takes an ID of the file that you want the user to download. Based on this key find the associated Domain instance. The domain should store the file name of the file. Then use this file name to resolve the file from the local file system (path configured in your application configuration). Open the file and stream the contents to the browser. Be sure to set he headers correctly to indicate the file name and size.
There are a lot of moving parts involved here but it can be done. Now, if you get stuck on something I suggest you post what you have tried and what's not working about it. Otherwise, the best we/I can do is give you general guidance/advice.
Hope this helps!
Edit
The real key is going to be in the controller for downloading the files. Here is a quick snippet of what that may look like:
String fileName = "something.zip" // should come from your domain instance
String filePathAndName = "/downloads/${fileName}" // should come from your configuration
response.setContentType("application/octet-stream")
response.setHeader("Content-disposition", "attachment;filename=${fileName")
// this will actually buffer/stream the file in 8k chunks instead of reading the entire file into memory.
org.apache.commons.io.IOUtils.copy((new File(filePathAndName)).openStream(), response.outputStream)
response.outputStream.flush()
response.outputStream.close()
I am want to export database table to a file.
I am using the following code, but it gives the following error.
String filename="D:/backup.txt";
I already create
st.executeQuery("select * from tamil into outfile'"+filename+"' fields terminated by ','");
But the error is:
java.sql.SQLException: Can't
create/write to file 'D:\backup.txt'
(Errcode: 13)
help me to clear the error
Thanks
But then you need to think how to put all this data into database.
You should consider mysqldump (or similar for other databases) http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Ever tried phpMyAdmin? You can easily manipulate your database with it.
Doesn't that error simply mean that you weren't allowed to write that file? Check if you can create a file with that name, in that location, for example using Notepad or by copying a file.
You need to remember that it will save it to the file on the computer that is running the database and NOT the computer running the java program. So for example, if the database computer is a Linux machine then
String filename="D:/backup.txt";
is definitely not going to work. So if you keep this in mind you can test why you cant write to D:/backup.txt.
The thing is, this error points to the fact your program is not able to access resources (files). Strange as it seems -you're in a windows environment-, you might check if the user which is executing your java app is allowed to create files in D:\
Also, as fazo stated, you'd consider using mysqldump, smart stuff which handles the whole process of setting data and schemas as well, into a file.
I am using Java to develop an application, it needs to manage the file on the computer. The application have the ability/function to delete the file on the system. But I want to check whether the selected file is using/reading by another application or not first. Because I don't want to delete the file which is reading/using. How can I do so?
Maybe you could use tryLock()?
On Windows, you can't delete files which are in use ("locked"). Java itself doesn't offer an API to check.
If another application is using the file or actively reading it, then provided that application has done its job correctly (opening the file with a read lock), you won't be able to delete the file -- you'll get an IOException (specifically, a sharing violation). Catch the exception to know whether there was a problem.