Creating database on client computer for java desktop application (swing) - java

I'm creating a java desktop application using swing which requires some database persistance for which I'm planning to use Hibernate. I'm pretty new to desktop application development so I wanted to know if and how the database can be created on the client computer when installed.
Is there a script to be run or maybe a hibernate configuration which initiates database creation?
A sample tutorial or example illustrating this will be ideal (although I was not able to find one).
Thanks in advance for any help provided.

Hibernate is not an database server itself, it is a object-relational mapping framework so you need a either embedded or stanalone database server. Java DB that comes with the JDK will be sufficent for desktop applications.

http://hamidseta.blogspot.in/2008/05/install-mysql-server-50-silently.html
In your package installer scripts perform the steps of silent MySql installation. In the BAT file put the code you find in the above link before triggering your Java application installer.
As per free licensing terms, one should not package MySql bundle for free, just check about the licensing if you bother.

I think it would be better if you can start with javaDB or SQLite.
They are perferred embedded database technologies for desktop java applications.
You can download the jar for sqlite-jdbc from here.
Take a look at few tutorials on JDBC
If you making swing applications, make sure you learn to use swing worker well. It will
be important to perform background processing.

Hibernate is Framework used as middle layer in project which interact between database and Business layer logic.
Hibernate features
J2EE integration
Object/Relational mapping
Automatic primary key generation
Object-oriented query language
So my suggestion is to go with MySQL because
Handles large databases. We use MySQL Server with databases that contain 50 million records. We also know of users who use MySQL Server with 60,000 tables and about 5,000,000,000 rows.
A very fast thread-based memory allocation system.
Very fast joins using an optimized one-sweep multi-join.
The server can provide error messages to clients in many languages.
This is only few features but you go to official site for more detail. And most important it's open source.
And the post help to install and configure on client system.

Related

Java Swing program with shared database on LAN

I am making an inventory management program which has a Swing GUI as front end, with multiple users on LAN sharing a database.
I have successfully made my GUI components and a local DB and run the program as per my requirements on a standalone pc(without networking).
Now, I need some insight as to how to scale my application to a network environment. I have already tried the following and it fails:
Having MSACCESS on one of the computers, I make a connection to the db with DriverManager.getConnection("jdbc:ucanaccess:////COMPUTER-PC/admin/DB.accdb");
All works well, however when 2 users are simultaneously connecting to the database, after certain update queries from both users, the data does not remain consistent. I am stuck here. How to manage the data and maintain consistency.
You're describing a 2-tier architecture (client-db).
In most cases you want to have the business logic, consistency check etc. on the backend and thus a 3-tier architecture (client-backend-db).
You can e.g. use Spring Boot to create a simple backend.
Spring Initializr can get you started e.g. with Spring Web (MVC), Spring Data JPA and H2 Database (if you don't need to use MS Access) module selected.
The downsides are:
you need a server to run the Spring Boot JAR. But you can also run it on the machine currently running MS Access.
you need to think about client-backend communication, e.g. using REST. But there are many samples on the Internet, e.g. using Spring RestTemplate or Spring WebClient.
Your question seems little basic to me .
This book by Martin Fowler is little old but It will give you a solid foundation .
Patterns of Enterprise Application Architecture Hardcover
by Martin Fowler

Local Java Application - Database Selection

I'd like to ask for your opinion on local databases for a java application i'm developing.
Its veterinary application, meaning I'll need to store Customer, Pet and Medical History details for a start. I know how to use JDBC but I've only used it online in applets.
So, I really dont know much about local solutions and how those gonna work when I'll publish the application in a .jar, so please guide me. Would MySQL still work?
Thanks!
This is fairly general question and light on details and MySQL sounds like it would work here. If this is for local-only access and a typical client-server model is not needed then I'd encourage looking into a database engine that can be loaded directly in the JVM. One of the benefits is that there is no need to install any separate database components and the JARs for the entire database engine can be packaged in your application.
Below are a few of these:
Apache Derby
HyperSQL
H2
SQLite - Some Java wrappers around the C library are available but there are not any pure Java JDBC drivers available for this that I am aware of.
I realize that it is not difficult for developers to configure MySQL for local use but it could lead to a number of support issues for end users. It may be possible to script the installation to preconfigure a large amount of it but I am not sure of the details of that and it would be an additional item for you to work out when packaging the application.
Some general questions about utilizing MySQL for this are shown below. It may very well be the best way to go but these are just some things to consider. Most of these are not really specific to the development of the application and are more on the support side of things. Utilizing a database engine noted above can eliminate all or many of these.
Will multiple computers every have to connect simultaneously to the same database?
What MySQL password do you use?
Do you recommend that end users all use the same one which may not be good security?
Or do the end users need to create one in which case you may need to deal with forgotten passwords and the end user having to configure the password in your application?
Do your end users run antivirus software that may interfere with the database connection?
What if they have another program that uses MySQL that is already using the default port?

Integrating data-provider to application without using sql or nosql servers

I'm creating a simple CMS software which doesn't have much data to be stored. I'm currently using mysql as my data provider and have a java application in the presentation layer. This CMS will be a standalone which means datacollection and processing will be done in a single computer.
I created a installer to install in my clients computers. But I need to setup mysql then the database as well. And my clients doesn't have sufficient IT knowledge to setup the databases themselves. So for each client I have to attend and install mysql server.
What I need is a way to integrate data-provider to the application without using mysql or any other sql or nosql server. So my clients can install it themselves using simple guided steps in installation wizards.
You can use one of embedded db, like JavaDB (ex. Derby). Support of this database is added to JRE. So all your client need is installed JRE. And you get full relational database without any installation and other stuff setup.
You can try using hsqldb or sqlite db. These dbs can be bundled with the application in memory or can use a simple file as db. Hope it helps
I found a good example here
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javadb/
thanks every one for help

JPA newbie can't interact with database

I started ussing JPA not long ago and I think it is great because of its annotations that make programming so simple. But I still have a lot few doubts that slow me down a bit (most of the times regarding to configuration issues):
I would like to understand the difference between the derby DB that comes in the OEPE(Oracle Enterprise Pack for Eclipse), I was using this for my learning, and the popular MySQL DB(www.mysql.com). What confuses me is what is the difference with an embedded DB an a non embedded. What is better, what do you recommend?
The second doubt is regarding to some configuration issue I can't fix with my derby DB(not embedded mode) I already made a question, but I could not fix it. The problem is that when I try to access some of the tables of my DB(The tables exist in the database, they were created by the JPA feature generate Tables from entities), I get SQLSyntaxErrorException saying that the tables don't exist. I know that is impossible because that same query manually inserted in eclipses scrapbook works correctly. I know this have something to do some configuration issue, but I don't know what is it.
I'll be really happy if someone with a bit more experience with JPA could give me a hand.
The tools I use for my programming are eclipse + OEPE, Java EE 6 and GlassfishV3.0
This is the link to my other question where I explain the issue in more detail:
SQLSyntaxErrorException: Table/View 'BUYER' does not exist. What is missing?
Thanks in advance.
Regarding question 1:
Derby/JavaDB has two operation modes (quoted form JavaDB documentation):
Embedded
Refers to Derby being started by a
simple single-user Java application.
With this option Derby runs in the
same Java virtual machine (JVM) as the
application. Derby can be almost
invisible to the end user because it
is started and stopped by the
application and often requires no
administration. The Derby
documentation often refers to this as
the embedded configuration or embedded
mode.
Server (or Server-based)
Refers to Derby being started by an
application that provides multi-user
connectivity to Derby databases across
a network. With this option Derby runs
in the Java virtual machine (JVM) that
hosts the Server. Applications connect
to the Server from different JVMs to
access the database. The Derby Network
Server is part of the Derby software
distribution and provides this type of
framework for Derby. Derby also works
well with other, independently
developed Server applications. The
Derby documentation often refers to
this as the Network Server
configuration or client/server
configuration.
From my experience, the main differences of both modes are that in embedded mode, the database is part of your application and only one user can connect to the database.
In server mode, the database is not part of your application, runs in a different JVM or on another machine and operates in multi-user/multi-connection mode.
Regarding comparison of JavaDB and MySQL, I think it depends on your application and functional requirements. A quick google search revealed this comparison of relational db systems (Derby can be found there under letter "A" for Apache Derby).

Java DB Client-server technology - centralized DB - How?

I have a project this year. It is about developing a Java application with a database for sharing and validating documents between the manager, secretary and head of finance.
My question is: How to make the database accessible by all, since the application will be installed on computers that I mentioned above, do I have to install it (the database) on these computers? The constraints of consistency and integrity of the database will be violated. The users will not have the same copy after each update!
Is there a possibility (or technology in Java) to put the database on the web and there will be accessible by all, or make it accessible from a computer that I realize as a server (client-server).
I would be grateful for your help or giving links for Tutorials.
How to make the database accessible by all, since the application will be installed on computers that I mentioned above, do I have to install it (the database) on these computers? The constraints of consistency and integrity of the database will be violated. The users will not have the same copy after each update!
Your question suggests that you will need one database on one computer. Let's call it a DB computer. I'd suggest this be a server, that no one from regular staff, such as secretary, manager, etc... can access.
Having one central database will eliminate your worries about integrity violation.
Now, you have two options. You can make a web application that your users will use to interact with your system. This is a more modern approach, since you'll have a 3 tier system:
users will access your application via a browser
the web application itself is stored on an application server, and it is accessing the database
the database is the backend part
The second option is making a desktop application and deploying it to everybody's computer that will use it; and afterwards making it connect to the database for interacting with it.
The first option is easier when you want to expose your application to a large number of users (and to the web), but know what you're doing when doing stuff like this, since you have to take security very seriously.
If you go the first route, you will need a few things:
First, a database. Use what you can, but if you need free and high quality databases, use PostgreSQL or MySQL.
Second, an application server. I suggest using Tomcat or GlassFish.
Now, you need to develop your application using JavaEE. There is a wealth of information about this, so I hope this will help you in the beginning and point you in the right direction.
Note that Tomcat doesn't support Java EE fully, but a subset of it. And this subset is surely more than enough for what you need to accomplish.
If I understand you correctly, you are looking for ways to implement a client-server system, where several clients on distinct computers each connect to a central server (or cluster of servers) hosting a DB. In Java, usually (but not necessarily) the DB is inside a web application, and the clients are lightweight web clients - in this case it is usually called an enterprise application.
Java has a whole dedicated SDK for this, called Java Enterprise Edition. You may find many questions dealing with this on SO, here are a few which I think may be especially helpful:
Is the offical Sun Java EE tutorial the best way to learn how to make Java web apps?
What to learn for making Java web applications in Java EE 6?

Categories

Resources