Export SQL database to mdb file (MS Access) using Java-Spring - java

I'm trying to export a SQL database to a mdb file, through my java-spring application, but I haven't found anything really useful.
The idea is to call a controller endpoint, which calls my service. There, I need to:
Execute a SQL query and get the result set
Return the mdb file, which contains just a new database with the table generated from the result set above
Download the ms-access file from the browser
How can this be achieved?
Thanks in advance
I haven't really tried many things, as the only way I seem to achieve this is by creating the mdb file directly in the client's computer and then opening a connection to execute a insert with the data, and that is not what I want to do. I'm stuck here

Related

Custom path for 1 Mongodb Database

I'm developing tool (in Java) that works with files on external HDD. According to my idea program and DB should store on external drive and work on any windows PC.
Could I somehow locate my mongodb database on this external HDD?
UPD.
To connect to DB I do:
mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost:27017"));
database = mongoClient.getDatabase("baseName");
How could I set path to DB files?
Since the paths change from one computer to another it will be hard to detect your database, also the case for multiple external hardrives connected to a computer would make this even worse.
My suggestion is this: Use a file chooser (JFileChooser in java) with the proper error messages in case the user selects the wrong files, that way you can always select your database and use it from any computer.

Connecting to a web-hosted database with java

I'm currently working on a project that requires me to connect our Java Project to a SQLite database with jdbc.
We've been using a database.db file located in the main/resources folder for a while without any issues. Now we're trying to switch to a hosted database, because this project is intended for multiple users and so far, we've had to include the database.db file with every git commit.
So, the most obvious first choice would be to instead of using the local resource, link to a hosted file. We have hosted our database.db file on a public server (yeah, yeah, but data security is not relevant for this project) and changed the resource to the hosted file, but it doesn't seem to work and returns "Resource not found" errors. We can't seem to get the syntax right. Here's what we have:
[...]
public Connection connectOrCreateDatabase(String databaseName) throws ClassNotFoundException, SQLException{
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:mysql:http://server.com/"+databaseName+".db");
[...]
Is there any way to get this to work?
Or is http just not supported at all?
Thanks in advance!
No, you can't use it over HTTP and pretend it's on the file system.
Why? You can read the db file over HTTP, but you can't write to it, making inserts and updates impossible.
You need to set it up in server mode and connect to it like a "real" database.

How do I recreate db and import JIRA data from previous automated export

I have my own local instance of Atlassian JIRA Issue Server on a hosted server. Unfortunately the hard-drive failed on the hosted server the administrator replaced the drive and recovered the program and data directories, but unfortunately the adminstrator had not actually made a back up of the database :(
Luckily it seems that JIRA automatically does a data export of the data, i have daily zip files such as 2015-Apr-20--0555.zip in
atlassian/application-data/jira/export
But what is the easiest way to import this data ?
The server is starting up but I can't access any admin pages, how do I go about recreating the database (i dont remember any details of how I did this the first time). Should I reinstall jira from scratch or can I fix the existing installation to accept the export file.
if the data exported as SQL then you can easy use MYSQLAdmin to import the data to the New JIRA Database, but if the data is comma separated file then you can use MYSQL command for that, based on what you say you cant do that because you cant reach to the server command windows, then you can create simple PHP file to insert the data from the zip file to the DB this link may help you
http://coyotelab.org/php/upload-csv-and-insert-into-database-using-phpmysql.html

Java application that can run entirely from a DVD

I have to create a java application that can run entirely from a DVD. The application must connect with a database that will be also on the DVD. I was thinking to use an embedded database but i dont know much about them. Do i have to start the database server from my java application and if i do, how should i do it?
Thanks in advance.
Nick Tsilivis
You can use SQLite which is a very light weighted version of SQL. It stores its data in a single file. You even don't have to log in with an username and password. Just add this jar sqlite-jdbc to your projects build path. You cann access it by following:
Class.forName("org.sqlite.JDBC");
Connection connection = DriverManager.getConnection("jdbc:sqlite:your_database.db"); //"your_database.db" is the SQLite database file on your DVD.
/*manipulate your db by using PreparedStatement, ResultSet, ...
You must have installed SQLite on your system SQLite Download
That sounds like a job for SQLite. It runs completely in your own process, so there is no need to start an external database server.

Export large data from DB to CSV

I need to export a Table into a CSV File and serve it to download via my JSF/Icefaces Webapplication.
How can I do that? I have a Table with 20+ Columns and over 10 MIO rows.
At the moment, I use a Java Thread, loading all data into ram. Then I create a new File and iterate the Collection writing row for row into the file. If the Thread is done, the user can download the large file via Servlet.
But I dont want to write so many GB into ram. I cant secure, not to get a memory problem..
Is it possible that hibernate does it for me? Or does somebody has an other idea?
Im connected to a DB2 Datebase. The table I want to export is connected to a hibernate bean but it is also possible to write native sql.
Thank you for response!
Do you need the intermediate stage of a file ? Have you tried loading from the database and writing to your servlet output stream for each row ? That way you're acting simply as a pipe between the client and the db.
Simply set your content-disposition header appropriately and that will signal the client's browser to treat the incoming data as a CSV file itself.
I have also gone through with similar kind of problem , the way I solve the problem is that I initially write a CSV file on disc and fetch 25K batch records from DB ans save to the file, and iteratively repeat the process until all the data required by the report is not written on the file.
And then send the file URL to the client to download the file.

Categories