I plan on making a distributed application where 10-15 computers are connected in a LAN and there is one server where the database will be stored, also inside the LAN.
For the purpose of the question lets say the application will be made using Java and the database will be MySQL, but that is not yet decided.
So the question is, what do I need to realize this?
I have ofcourse worked with MySQL databases, but on a single computer so I am not quite sure how to connect the computers to the database server. Is it enough to setup the server local IP on all client computers and connect to it using the JDBC MySQL driver, and after that I can work with it like the DB is on my machine?
Also, do I need a server application to manage connections to the database, so that there are no conflicting entries? And if I do, then the connection part changes, because it needs to be established over the server application, so how do I do that?
I know it is a large question, but a lot of things seem unclear, because I have never attempted a project this big.
Thank you all!
Don't worry just made your application, you can connect to your database via an #IP, so just make a part of configuration in your application to change some information in future:
String db_url = "jdbc:mysql://192.168.0.1/db_test";
Is it enough to setup the server local IP on all client computers and
connect to it using the JDBC MySQL driver, and after that I can work
with it like the DB is on my machine
You don't need a server local of every computer, you can connect to the server directly.
Also, do I need a server application to manage connections to the
database, so that there are no conflicting entries? And if I do, then
the connection part changes, because it needs to be established over
the server application, so how do I do that?
If you are using a desktop application, the you don't need a server application, else if you are using a web application, yes you need one.
You need to shouse a server application, this dippend of your project or your company, there are free servers like GlassFish, Payara, Apache Tomcat, Wildfly and more.
Now the connection to your database, there are many ways to connect to your database, if you are using JPA to connect to your database, then you will hear
something about Entities, Facades, JNDI so this generally be configure in your server
application.
Hope you get an idea.
Related
I am working in an application that connect to a PostgreSQL Database and will allow to access from differents computers connected in the same local network.
It's already working, but when it is used in more than one computer at the same time, the server disconnect the current computer to attend to a new connection.
There's some way to make that the PostgreSQL server attend to more than one computer at time?
I think that maybe, I'm doing something wrong in the way that I'm using the server.
When the application start I set the pgdata and pgport variables and check the server status with pg_isready, if it has no answer, I use pg_ctl start.
I'm using the 3389 port.
EDIT:
My problem was a logic error in the application, it was trying to open a new server with each connection instead of use the one that was already running.
The configuration file 'C:\Program Files\PostgreSQL\Y.X\data\postgresql.conf' has a parameter called max_connections, which controls the maximun numbers of connections allowed to your DB. Change it and you can allow more connections after restarting postgres.
I am fairly new to H2 Database. As a part of a PoC, I am using H2 database(version : 1.4.187) for mocking the MS SQL Server DB. I have one application, say app1 which generates the data and save into H2. Another application, app2, needs to read from the H2 database and process the data it reads. I am trying to use Auto Server mode so that even if one of the application is down, other one is able to read/write to/from the database.
After reading multiple examples, i found how to build the h2 url and shown as below:
jdbc:h2:~/datafactory;MODE=MSSQLServer;AUTO_SERVER=TRUE;
Enabled the tcp and remote access as Below:
org.h2.tools.Server.createTcpServer("-tcpAllowOthers","-webAllowOthers").start()
With this, I am able to write to the database. Now, I want to read the data using the h2-web-console application. I am able to do that from my local machine. However, I am not able to understand how I can connect to this database remotely from another machine.
My plant is to run these two apps in an ubuntu machine and I can monitor the data using the web console from my machine. Is it not possible with this approach?
How can I solve this ?
Or do I need to use server mode and explicitly start the h2 server? Any help would be appreciated.
By default, remote connections are disabled for H2 database for protection. To enable remote access to the TCP server, you need to start the TCP server using the option -tcpAllowOthers or the other flags -webAllowOthers, -pgAllowOthers
.
To start both the Web Console server (the H2 Console tool) and the TCP server with remote connections enabled, you will have to use something like below
java -jar /path/to/h2.jar -web -webAllowOthers -tcp -tcpAllowOthers -browser
More information can be found in the docs here and console settings can be configured from here
Not entirely sure but looking at the documentation and other questions answered previously regarding the same topic the url should be something like this:
jdbc:h2:tcp://<host>:<port>/~/datafactory;MODE=MSSQLServer;AUTO_SERVER=TRUE;
It seems that the host may not be localhost and the database may not be in memory
Is there a need for the H2 web console?
You can use a different SQL tool using the TCP server you have already started. I use SQuirreL SQL Client (http://squirrel-sql.sourceforge.net/) to connect to different databases.
If you need a web interface you could use Adminer (https://www.adminer.org/) which can connect to different database vendors, including MS SQL, which happens to be mode you're running H2. There is an Adminer Debian package that should work for Ubuntu.
I am planing to but a web hosting package to host a site which shows customer details to the customers who will be registered with that web site. I have a java application which runs in my local computer which I am going to update the database of my hosted web site.
What in need to know is, is that possible to connect to the databases which we are buying from the web hosting package sellers from our locally running java applications?
Q: is it possible to connect to the databases which we are buying from the web hosting package sellers from our locally running java applications?
A: No: not usually.
At a MINIMUM, you need at LEAST two things:
1) RDBMS-specific client software (including, but not necessarily limited to, the relevant JDBC driver(s)) loaded on to EACH client PC
... and ...
2) All firewalls between the remote RDBMS server and each of your client PCs must be open to your RDBMS protocol (for example, port 1433 for MS Sql Server).
It's much more common for your web app, web server and RDBMS to be co-located, and your clients simply communicate via HTTPS.
Yes it's possible to connect to remote databases using java applications. The JDBC API will help you to create tables, insert values, query the tables, retrieve the results of the queries, and update the tables.
As far as a remote connection is concerned, here are two good links to begin with:
1) Link 1
2) Link 2
You haven't specified the type of database you need to connect to. Depending upon that you can learn how to create data sources, database roles etc as shown over here.
First of all, we are running a Java Web application running on WAS 5.1. Behind that, we use an Oracle data base. The problem that we're faced to is really simple, but after a couple of hours of Google search, I decided to ask you.
We have an application that is running on WAS. When we start the server, WAS sets his DataSource so that it points to the data base. Everything works fine, expect when the DBAs have to reboot the data base server. When they do, the data source is no longer valid and we have to manually restart all server and we are currently trying to correct that, if possible. We need to find a way to do it because we have 3 pre-production environnement for for our application, and there are two servers associated with it, one for the application and the other is a report generator web service. So, when the DBAs wants to reboot the server (and they usually don't tell us!) we have to reboot six servers. I was wondering if in Java, there was a way to reset the data source so that we don't need to restart the servers.
For you information, WebSphere is v5.1 and Oracle is 9g with Java 1.4.2.17.
We also use RAD:
Version: 6.0.1
Build id: 20050725_1800
You should configure your application server to always test the connection before leasing it out to a client. I'm not familiar with Websphere that much, but in WebLogic, you can set a jdbc sql statement such as select 1 from dual and the container removes stale connections from the connection pool.
Here is a link on how to do it in Websphere
http://www-01.ibm.com/support/docview.wss?uid=swg21439688
Based on what i read from your note, you should receive Stale connection exception as WAS has stale handles (in its pool) as the DB has been restarted.
The Data Source configuration can be configured to purge the entire pool once a stale connection is detected. The default policy is to purge the individual connection.
Adopting this would prevent you from restarting your WAS Servers.
There are a number of resources in this space
http://www-01.ibm.com/support/docview.wss?uid=swg21063645
HTH
Manglu
I have a Java application and I have to connect to a MySQL DB host in aruba.it. If I make a connection, aruba.it refuses that. How to solve this?
To start, I assume that you're trying to run this Java application locally, or at least at a different machine than where the MySQL DB runs and that you got a SQLException: Connection Refused.
To fix the particular problem, all routers and firewalls in the complete network pipe between the client (where the Java application runs) and the server (where the MySQL DB runs) needs to be configured to allow/forward the port number which the DB uses. This is by default 3306. If this port is blocked, you cannot reach the DB from outside.
Another solution is just to upload the Java application in flavor of a webapplication and run it by HTTP. You'd normally use JSP/Servlet for this.
Apart from network, routers, firewall issues the reason can be that by default remote access to MySQL database server is disabled for security reasons. Mostly DB is hosted on the same server or on the trusted server. If you run java application from your desktop, you need to configure MySQL so it will accept this connections. See this manual for details how to do it.