Derby access in IntelliJ? - java

I'm trying to learn the basics of database access, and I chose to use Derby. I'm using Embedder Derby, and I have IntelliJ set up so that it connects to Derby. However, when IntelliJ is connected to the database, my applications cannot access it. I know that I have to disconnect from the database from IntelliJ before attempting to access it with my application. Is there a way to set it up so that I can access the database with both IntelliJ and my application at the same time?

You cannot access the Embedded Database from more than one process, because when you run the Apache Derby database in embedded mode, only one Java process is created. The database process becomes an integral part of the process in which it was created.
However, you can use client/server mode to access the database with more than one application.

Related

How to open the java application with database to another computer

Should I do the "Embedded Database" if I want the program I created with the database to be able to access another computer?
I finally export my Java application as an executable file/application file, but my only problem is that its database needs to be always connected to the database I created. So, when I run it, It runs perfectly but I cannot access my database unless the NetBeans is running in the background. But I want it to be able to run independently without NetBeans and needing to connect to the database every time so that I can run it to my other computer. I read that I should create an embedded database so that when I try to open the file to another computer, the database is included.
Is my understanding right? I created a database using JDBC.
if you want to connect to your database in other computer,you'd better create your database on Server which connected to the Internet.
It depends on the type of application which you are going to develop.
If your application is a single-user standalone system then it's perfectly fine to use an embedded database. Example: Single-player game.(In here application's database is hosted within the user's machine so other users can't access those data)
But if you are developing an application which is having more than one user and those users need to share their data with others then you should go for a database like Amazon RDS which is hosted on the cloud, because then you can share those data among all the users.
(Ex: Microsoft Teams Application)
Finally, I should say yes you don't need to have NetBeans working if you select either one of those options.

Android app extern database server

When I want to create an SQLite external database for android application, do I have to have a server with database that is always running?
Yes, since it will be on a server. If the server isn't running, then your application won't be able to get any data from the database.
There's a very important distinction that we're missing here - what it means to have a remote database.
SQLite is a flat-file embedded database engine. You don't have a separate process running SQLite in the background like you would one for MySQL or PostgreSQL or Oracle, nor would you really want to - SQLite as a database is pretty limited in what it can do.
If you say that you're going to have a remote SQLite database, then that implies that you have some server somewhere that writes to and reads from this flat-file database. If you can finagle that somehow, and make it secure, then more power to you - and yes, you could have this accessible remotely for your intents and purposes. Trust me though, you wouldn't want to.
What you're likely looking for is a way to remotely run MySQL or PostgreSQL instead, as these are proper database management systems (DBMS) which will be able to both service remote connections and give you a more expanded set of the SQL language.
Ultimately though, the database server must be running at all times. You wouldn't be able to connect to the database if it's down, and you don't know the lifespan of the app (or when it's going to be accessed, etc).
i got the below information from SQLite home page
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
Based on the above statement you don't any server. I hope this information is useful to you.

Desktop app with local and online database

I want to create a Desktop App(Software), preferably in Java, which connects to a central MySQL DB on a local network whenever available.
I also want it to store and use a copy of the same DB when the central DB is not available, and sync whenever the central DB is available.
How can I store data locally, I mean which kind of database should I use for local database?
Also, are there any tools which speed up the Desktop App development?
Let's suppose that you will implement your solution in Java. You will need some classes (i.e. Data Access Obejcts, DAOs) in charge of interacting with the database on the network and on a file based database embedded in the application (the "local" database).
What you need:
A local database that you can ship with your application like H2 www.h2database.com, HSQLDB http://hsqldb.org/ or Derby db.apache.org/derby/.
To develop your DAOs (using JDBC or Hibernate) in such a way that you can instantiate them with different drivers, URLs, login/pwd and use only SQL standard / functions supported both by MySql and by the local DBMS. In practice you must avoid using DB specific functions.
You can use Hibernate or JPA for example, they have quite a nice and easy integration with your application.

Why h2 and mysql database locations are different in eclipse?

This is a stupid question and I know it, nevertheless I'd like to understand how these two databases are handled within my system.
I have eclipse IDE with two projects: h2_test and mysql_test, where h2_test is configured to use h2 database and mysql_test is configured to use mysql database.
In h2_test I have h2 location configured as String url = "jdbc:h2:~/h2_db" whereas in mysql_test as <property name="url" value="jdbc:mysql://localhost:3306/mysql"/>. As you might have guessed h2_test is a normal java project and mysql_test is dynamic web project.
When I run my h2_db my h2 database instance is created on my hard drive at ~/ directory.
When I run my msql_db my mysql database instance is created in memory?
I must add that to actually run mysql I had to install it and run as a system.service while for h2 all I had to do is to connect a h2 driver in eclipse. Why so much hassle with mysql?
Why I can't use the same logic with mysql db and create is as jdbc:mysql:~/mysql_db?
How are these set-ups different and which one is preferable for a web application?
h2 DB is a standalone database, that a single Java application loads directly and operates on. Usually, a single application can use a DB at a time. Other DBs of this sort are the key-value LevelDB and Java's DB4O.
MySQL, on the other hand, is designed to be more powerful, in that it is run in a server process (written in C++). Applications (a large number simultaneously) can connect to a given MySQL server (with authentication), even from different hosts.

Can I use an embedded Derby database in a client-server db environment one in future?

Can I use an embedded Derby database as non-embedded one in future? In this case will I need to migration or I will just need to change the driver in jdbc? If it is more complicated what will I have to do?
Yes, you can. A Derby database is identical, whether it's accessed by a standalone program using the embedded driver, or by multiple client programs communicating with the Derby network server.
The Derby network server is just some "glue" software which implements the DRDA remote database protocols to implement JDBC-over-the-net and then uses the normal embedded database access to access your database on the server side.
If you wish, there is even a slightly more advanced configuration called the "embedded server" which allows you to have your program which uses the embedded driver to access your database share that access with other networked clients by simultaneously acting as a networked server.
Here's some more information about that last option: http://db.apache.org/derby/docs/10.10/adminguide/radminembeddedserverex.html

Categories

Resources