I'm trying to make a java application that connects to a database that is not located on my pc. I'm not sure how to do this. If I create my own database with MySQL, where do i need to store the database in order to acces it from other computers. I want to know what do I need in order to do this. I checked the internet and saw a lot of examples using jdbc and connecting to a url with localhost or something like this. Thank you!
Local: the server address will be 'localhost' or '127.0.0.1'
You can install mysql on your computer and connect to it with the computer's ip (generally 192.168.1.??). You can install LAMP or MAMP to have mysql working easily on your network ('put online' option).
Internet: the server adresse is given by your host, replace the 'localhost' or '127.0.0.1' address on the jdbc parameters.
I'm banging my head hard.
This simple line of code:
DriverManager.getConnection("jdbc:mysql://machine1:3306/information_schema", "user1", "password");
Running on machine1 results in an error:
1045 Access denied for user 'user1'#'localhost' (using password: YES)
However there's no problem running on machine2 or any other machine for that matter.
user1 actually has two different passwords, one is password if the connection is made to machine1 (which is the machine name), one is password1 if the connection is made to localhost.
That sounds crazy but our IT department insists that it is for security purposes. So if you can ignore the madness of that, the problem is obvious: I asked JDBC to connect to machine1 with username user1 and password password, which is correct, but it somehow tries to connect to localhost and hence the error.
I suspect that on machine1, there's some sort of configuration that delegates all internal connection from machine1 to localhost. That's why the error only occurs when I run that command from machine1, and never occurs if I run it from elsewhere.
Modify the code to connect to localhost will work but the framework does not allow me to do that.
Any idea?
I hate this when I bang my head against the wall for 5 hours and the moment after I post the question on SO I find the answer.
The problem is that in /etc/host, machine1 points to the same address as localhost (127.0.0.1). Modify the file to have machine1 point to the real IP address (e.g. 10.240.3.167) will solve the problem.
Are you running this code on machine1? In that case the error is correct because localhost is itself. Have you tried connecting via the MySQL command line from the same machine running your code? I suspect the credentials aren't set up in MySQL to allow connections from localhost.
I just re-read. You need to use the localhost password when connecting from machine1. MySQL uses #localhost as where the connection is coming from. What value jdbc used for dns is not relevant.
hello guys i have seen similar threads concerning my question but couldn't solve my problem. i am trying to remotely connect to the mysql database hosted on cpanel through my netbeans. i have added my ip address as a host to be allowed remote access. the cpanel ip address was given as https:197.211.45.2:2087. the username given as 'root' and the password also given. in my netbeans i try connecting to the database using the stated parameters and the database name but it wouldnt just connect. i have also tried using the default mysql port it still wouldnt work. if there is anything wrong i have done please put me aright. thanksthe image.. i have attached a snapshot. thanks
It's seems that MySQL port is not added in server firewall and due to that you are getting this issues. Please add port 3306 in firewall and check again.
Under cPanel there is usually 'Remote MySQL' tool which allows you to enter the IP addresses that are allowed to connect into the host.
i want to add database to my netbeans java project using ip address.
my question is that when i specify hostname by name that is "localhost" followed my correct details in the new connection wizard in netbeans connection establishes succesfully. this is as shown below.
but when i specify host by specifying ip address of my own computer that is localhost connection doesn't get established. same is shown below
well my motive is not to put ip of localhost but of another pc for remote database sharing over internet. but i think the problem lies in the method of specifying host using ip. if i get it right database sharing might work between different hosts as well.
also any other methods of sharing postgres database over the internet are also welcome.
i am a newbie in java as well as netbeans so any help is appreciated.
Your sense of thinking that localhost is your IP-Address is itself wrong!You need to have a loop-back address which will direct your operations to itself and not as the case of your IP-Address shown in ipconfig command.
You need to specify this 127.0.0.1 as the IP-Address.
127.0.0.1 is the most-commonly used IPv4 loopback address.
Try this :- jdbc:postgresql://127.0.0.1:5432/nic_project_db
localhost means this computer. It is a hostname that the computer's
software and users may employ to access the computer's own network
services via its loopback network interface. Using the loopback
interface bypasses local network interface hardware. // Taken from Wikipedia.
For future reference to anyone that might have same question here is solution:
In the postgresql database folder open up the postgresql.conf file. Add the following line:
listen_addresses = '*'
Then open up the pg_hba.conf file and add the following line:
host all all 0.0.0.0/0 md5
I am new to Oracle, and am trying to run a simple example code with Java, but am getting this error when executing the code.. I am able to start up the listener via CMD and am also able to run SQL Plus. Can anyone give me a hand and tell me what I might be doing wrong?
Update:
I am using JDBC.
Database is local, and I actually had it working but it stopped working just today. I'm not really sure why though. Would you mind giving me some procedures to follow by since I don't know much.
Either:
The database isn't running
You got the URL wrong
There is a firewall in the way.
(This strange error message is produced by Oracle's JDBC driver when it can't connect to the database server. 'Network adapter' appears to refer to some component of their code, which isn't very useful. Real network adapters (NICs) don't establish connections at all: TCP protocol stacks do that. It would have been a lot more useful if they had just let the original ConnectException be thrown, or at least used its error message and let it appear in the stack trace.)
I had the same problem, and this is how I fixed it.
I was using the wrong port for my connection.
private final String DB_URL = "jdbc:oracle:thin:#localhost:1521:orcll"; // 1521 my wrong port
go to your localhost
(my localhost address) : https://localhost:1158/em
login
user name
password
connect as --> normal
Below 'General' click on LISTENER_localhost
look at you port number
Net Address (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522))
Connect to port 1522
Edit you connection
change port 1521 to 1522.
done
Another thing you might want to check that the listener.ora file matches the way you are trying to connect to the DB. If you were connecting via a localhost reference and your listener.ora file got changed from:
HOST = localhost
to
HOST = 192.168.XX.XX
then this can cause the error that you had unless you update your hosts file to accommodate for this. Someone might have made this change to allow for remote connections to the DB from other machines.
I figured out that in my case, my database was in different subnet than the subnet from where i was trying to access the db.
I had this error when i renamed the pc in the windows-properties. The pc-name must be updated in the listener.ora-file
Most probably you have listener configured wrongly, the hostname you specify in connection string must be the same as in the listener.
First check the Firewall and network related issues.
Check if Oracle Listener service is available and running. If not you may use Oracle Net Configuration Assistant tool to add and register new listener.
If the above steps are ok then you need to configure Oracle Listener appropriately. You may use Oracle Net Manager tool or edit “%ORACLE_HOME%\network\admin\listener.ora” file manually.
There are 2 options that need to be considered carefully:
Listening Locations associated with the Listener – Hostname(IP) and Port in Listening Location must exactly match the ones used in the connection string.
For example, if you use 192.168.74.139 as target hostname, then there must be Listening Location registered with the same IP address.
Also make sure the you use the same SID as indicated in Database Service associated with the Listener.
https://adhoctuts.com/fix-oracle-io-error-the-network-adapter-could-not-establish-the-connection-error/
IO Error: The Network Adapter could not establish the connection (CONNECTION_ID=iKQM6lBbSLiArrYuDqud8A==)
if you are facing this issue
1- make sure you have downloaded oracle databases like oracle 11g,19c, 21c, or any latest databases.
2- search for services in your computer or type win+r then services.mis then search for oracleservice you will find orcl or xe or any other sid like oracleserviceorcl;
after that you can test your connection using sql developer, sql plus or cmd
To resolve the Network Adapter Error I had to remove the - in the name of the computer name.
In my case, I needed to specify a viahost and viauser. Worth trying if you're in a complex system. :)
For me the basic oracle only was not installed. Please ensure you have oracle installed and then try checking host and port.
I was having issues with this as well. I was using the jdbc connection string to connect to the database. The hostname was incorrectly configured in the string. I am using Mac, and the same string was being used on Windows machines without an issue. On my connection string, I had to make sure that I had the full url with the appending "organizationname.com" to the end of the hostname.
Hope this helps.
Just try to re-create connection. In my situation one of jdbc connection stopped working for no reason. From console sqlplus was working ok.
It took me 2 hours to realize that If i create the same connection - it works.