Java, MySql -- connecting from another computer - java

I created a java program that uses MySql. Now I want to give the app to someone else, and I'm using the URL as: jdbc:mysql://ipAddress:3306/tableName, but it doesn't work, showing the error of connection failure.
What should I do?

It's a troubleshooting stuff, do the following.
Check the Firewall and Port access on MySQL Server computer.
Check the MySQL Service and the DB User is doing good.
Follow the following thread
How to allow remote connection to mysql

Related

java application not connect with a specific database in mysql on localhost,connection refused error comes

My java application is not connect with a specific database in MySQL on local host.'Connection refused' named error coming when I am trying to connect.
I have checked also service of MySQL its working because there is two db on local host, I am able to connect with one Db. I have googled all the things but my problem still not resolved.
Please check the Bind address
(https://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_bind-address) to see if you have altered the my.cnf|ini configuration file on mysql correctly.
Also if you are trying to connect using different machine then you have to create a user and grant him privileges like this to make the database available remotely
CREATE USER 'jeffrey'#'%' IDENTIFIED BY 'mypass';
GRANT ALL ON db1.* TO 'jeffrey'#'%';
Wildcard % is used to give access to any IP connecting your machine.

Unable to Access and Connect to MySQL Server Data Base

I am totally new to MySQL Server but good at Java! I know how to connect with the MySQL Server using Java. Recently, I have made a simple small MySQL Server (Test) app for me. Its just for my knowledge! I have successfully connected to the database and successful to use INSERT and SELECT Statements in my Java App.
The problem is that my app is only running on my that laptop on which the SQL Server 2008R2 is installed on! I just checked my app on my another Laptop and it says the following error:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP
connection to the host localhost, port 1433 has failed. Error:
"Connection refused: connect. Verify the connection properties.
Make sure that an instance of SQL Server is running on the host
and accepting TCP/IP connections at the port. Make sure that TCP
connections to the port are not blocked by a firewall.
I have tried this link so far no Success an still I can't access my Data Base on my other machine!
msdn.microsoft.com/en-us/library/ms175043.aspx
From an answer i also tried my best!
stackoverflow.com/a/12430561/2496503
From this answer i have come to know that my SQL Server Network Configuration(32-bit) is not showing any details/options as mentioned in the above answer here is a snapshot attached herewith !
PLEASE TELL ME IF IT IS ORDINARY THING THAT IT IS NOT SHOWING ANY OPTIONS! ELSE MY SQL SERVER ISN'T INSTALLED CORRECTLY PLEASE HELP ME GIVE ME JUST HINTS I WILL BE THANKFUL TO YOU !
Perform these Steps for TCP/IP network Configuration upto step 6, ur problem will be solved.
[http://www.visual-paradigm.com/support/articles/solve-sql-server-connection-problem.jsp][1]

How to connect to a remote database with JDBC?

I'm trying to connect to a remote database via JDBC. Here's my connection string:
db=mysql://user:password#blablabla.rds.amazonaws.com/dbname
At a first glance it seems like it should work, but on trying it, I get the error:
Cannot connected to the database, An attempt by a client to checkout a Connection has timed out.
I'm trying to use Play framework (1.2.x) and have described this db connection in the conf file.
Any ideas?
Following on from duffymo, the string you want to use is jdbc:mysql://blablabla.rds.amazonaws.com/dbname?user=user&password=password as documented here
Yes, this is the wrong URL.
You need the MySQL Connector-J JDBC driver JAR in your CLASSPATH.
The URL should look like this:
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
I would recommend not putting the credentials in the URL. Add them in Java.
If you're getting an error, please post the stack trace. That will help to diagnose what you did wrong.
Can you connect to that database using the MySQL admin tool? Can you ping that server? Can you telnet to that port? If not, Java won't connect, either. Is there a firewall between your client machine and the database server? If yes, then the MySQL port has to be open for you.

IO Error: The Network Adapter could not establish the connection

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.

JDBC: Oracle Application Server and "The Network Adapter could not establish the connection" error

I am getting the error: "The Network Adapter could not establish the connection" from a web application deployed in Oracle Application Server 10g. The database is local, so there shouldn't be any connection issues.
First test: I can connect to the DB no problem from SQL plus, run queries, etc.
Second test: I can connect to the database no problem from a locally installed JDeveloper on the server, and run queries, etc. no problem. This works with the short JDBC scring, and the long one (shown below).
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=abcd)(SERVER=DEDICATED)))
Yet when I run the web app, it gives the above error. It seems too generic for me to do anything about.
Any suggestions on how to solve this? I assume that Oracle logs failed connection attempts somewhere, but I couldn't find anything relevant in the databases alert.log file.
It is possible that the problem is that the application is using an old jsdk, but I would assume that then some version mismatch error would be given instead of a "network connection" message.
Edit: I don't know whether this is an OAS problem or a problem with the specific Web Application, I would like to figure this out first, as it seems it should be easy. In WebSphere, there is a "test connection" button to dest data-sources you have added, but it seems there is no such functionality in OAS10? Somehow I think there must be, and I am just missing it because I am not an OAS expert.
Edit 2: I installed JDevelop on a remote machine and connected to the database with no problems, so I know for sure it isn't an issue with the database connectivity itself - it seems like it must be a problem within OAS?
I faced similar problem(able to connect through client but not web application) with Oracle XE when running with default configuration. Increasing number of sessions and processes solved my problem. Check this http://www.markcallen.com/oracle/oracle-xe-tuning.
I assume that Oracle logs failed connection attempts somewhere
It would show up in listener.log, but with the error you get, it seems doubtful that JDBC could even contact the listener.
jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=abcd)(SERVER=DEDICATED)))
Is that the same string you use for the web app?
I've had issues with localhost and 127.0.0.1 which go away when using a more definitive host name or address [IE a name that other machines would know the host as.]. I think it was to do with how the name was resolved (eg locally or off to a name server or similar).
Not a java person, but is there any way to simply ping localhost/127.0.0.1 from the java and see whether there's a response.
One of the ways to fix the issueis to update Hosts file at WAS Server with entries for DB servers as shown below:
111.222.333.444 serverab.abc.com serverab

Categories