connecting to mysql database failing - java

Most recent problem is "Third Error" listed below.
I am working on an application in java that needs to connect to a database. Below is the code that i am using to attempt to connect to the database. The port is 3306 and i have the database set up on a machine here at my house on the network. For the ip address i am just using my external ip address to the world. The username and password were replaced for my protection. In my /etc/mysql/my.cnf, "bind_address" is commented out.
I have tried several things and can not seem to get this to work. This is my first time using JDBC... thanks for any help! Let me know if you need more information.
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("before connection");
connect = DriverManager.getConnection("jdbc:mysql://ip-address/mjla_db", "username", "password");
System.out.println("connection established");
Here is the error that i keep getting:
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2332)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at school.cs321.mjla.MJLA.main(MJLA.java:30)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
... 15 more
Second Error
After changing ip address to the internal ip address of the server.
java.sql.SQLException: null, message from server: "Host '192.168.1.102' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1128)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at school.cs321.mjla.MJLA.main(MJLA.java:30)
Third error
When trying to access the database with the external ip address on an external network, i get the same error that i had initially.
I am using the "%" wild card for the Host of the username i am using for the application to authenticate to the database.

#Dave Newton: I was making the assumption that my firewall still had the port open for mysql, because i just got through working on a project where i did the same thing. However, i must have closed it a couple months ago. I checked a few minutes ago and it was disabled. So, i enabled and it is working fine now. Not sure why it had been closed...

Are you sure that the IP address in getConnection is correct? Can you try with
telnet youserver 3306
to see if there is a connection problem? Is there a firewall on the server?

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/student", "root", "root");
just try it

Related

Java.rmi.ConnectException: Connection refused to host: localhost

So i have read up on similar questions but i haven't found anything that i fully understand yet.
http://www.coderanch.com/t/487650/java/java/java-rmi-ConnectException-Connection-refused
http://protegewiki.stanford.edu/wiki/Troubleshooting_Client_Server_Connections
what is RMI registry
http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/faq.html#domain
I have a server which is crashing every few days and I am trying to work out where the problem lies. The software is running in an environment supplied by the customer and i need to know if we are the problem or windows/the network.
My question is... RMI registry, Is that something that java creates or is it something that exists in windows anyway? Why would a connection to localhost suddenly become unavailable or refused? Is there anything that i can do to troubleshoot immediately?
The RMI configuration is here:
<RMIService>
<class>com.s.i.system.RMIService</class>
<server name="Server">
<host>localhost</host>
<timeout>0</timeout>
</server>
</RMIService>
Here is the error that is created in the logs.
2015-04-02 16:52:10,057 ERROR [main] com...........gui.initialise.ClientInitialise - java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Unknown Source)
at com.s.i.system.RMIService.lookup(RMIService.java:570)
at com.s.i.system.RMIService.lookupServer(RMIService.java:377)
at com.s.i.process.RemoteRequestHandler$Dispatcher.run(RemoteRequestHandler.java:282)
at com.s.i.process.RemoteRequestHandler$Dispatcher.start(RemoteRequestHandler.java:269)
at com.s.i.process.RemoteRequestHandler.handle(RemoteRequestHandler.java:96)
at com.s.i.process.RequestDispatcher.dispatch(RequestDispatcher.java:136)
at com.s.i.client.ClientInitialiser.initialiseEnvironment(ClientInitialiser.java:498)
at com.s.i.client.ClientInitialiser.performEnvironmentInit(ClientInitialiser.java:145)
at com.s.i.client.ClientInitialiser.initialise(ClientInitialiser.java:128)
at com.s.i.client.ClientInitialiser.initialise(ClientInitialiser.java:106)
at com.s.i.gui.initialise.ClientInitialise.createInitialiser(ClientInitialise.java:136)
at com.s.i.gui.initialise.ClientInitialise.<init>(ClientInitialise.java:155)
at com.s.i.client.Client.initialise(Client.java:118)
at com.s.i.client.Client.main(Client.java:147)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
... 20 more
The RMI Registry is a component of the JRE, not of Windows. Clearly it is crashing, or far more probably it is being closed down incorrectly for some reason. I've never seen an RMI Registry crash in 18 years.

How to install Openfire on windows 8.1 64-bit with external database

I try to install openfire but I have some error, I don't understand why I cannot install successfully Openfire 3.9.3 . when I choose : Standard Database Connection
Use an external database with the built-in connection pool.
=> I use http://localhost/phpmyadmin/ for mysql
Database Driver Presets:MySql
JDBC Driver Class:com.mysql.jdbc.Driver
Database URL:jdbc:mysql://[localhost]:3306/[dbopenfire]?rewriteBatchedStatements=true
Username:root
//Left blank
Password:
what is the problem?
many thanks.
error.log:
2014.07.27 20:57:33 org.jivesoftware.util.log.util.CommonsLogFactory - Prototype
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.GeneratedConstructorAccessor13.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2539)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2321)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.logicalcobwebs.proxool.DefaultConnectionBuilder.buildConnection(DefaultConnectionBuilder.java:39)
at org.logicalcobwebs.proxool.Prototyper.buildConnection(Prototyper.java:159)
at org.logicalcobwebs.proxool.Prototyper.sweep(Prototyper.java:102)
at org.logicalcobwebs.proxool.PrototyperThread.run(PrototyperThread.java:44)
Caused by: java.net.UnknownHostException: [localhost]
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:250)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 17 more
2014.07.27 20:58:03 org.jivesoftware.util.log.util.CommonsLogFactory - Prototype
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.GeneratedConstructorAccessor13.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1127)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2539)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2321)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.logicalcobwebs.proxool.DefaultConnectionBuilder.buildConnection(DefaultConnectionBuilder.java:39)
at org.logicalcobwebs.proxool.Prototyper.buildConnection(Prototyper.java:159)
at org.logicalcobwebs.proxool.Prototyper.sweep(Prototyper.java:102)
at org.logicalcobwebs.proxool.PrototyperThread.run(PrototyperThread.java:44)
Caused by: java.net.UnknownHostException: [localhost]
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:250)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 17 more

Communications link failure issue (How to test for URL)

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Anime {
public static void main(String[] args) {
String url = "jdbc:mysql://xx.xxx.xxx.xx:3306/wordpress";
String user_name = "root";
String pass = "mypassword_is_here";
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection(url,user_name, pass);
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
And I keep getting this error
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:344)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2332)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Anime.main(Anime.java:17)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:257)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:294)
... 15 more
Now I've looked around stackoverflow and it seems like this is usually because the url isn't correct or sometimes there is a firewall issue or the wait_timeout variable in mysql is too low (it isn't in my case).
By the way, I am trying to connect to an external database on a centOS linux server running mySQL.
So I'm wondering how I can test the URL outside the program to really see if it's because of the URL or the firewall or any of that for the matter. If you guys got any solutions, please let me know.

Connecting to a Remote Database through Java

I have a mysql database created on a raspberry pi, I want to access it through a java application running on a laptop in the same local network.
I tried connecting that same application with another database on another computer on the network and it worked. I don't know why it isn't working with the RPI.
i connect through the following command:
String URL = "jdbc:mysql://192.168.11.157/DB_name";
try {
connection = DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
However, an exception is thrown and ERROR: Unable to Connect to Database. is printed to the console.
Edit:
Knowing that:
* I can access the database through a local app running on the same raspberry pi (i used #local).
* Can Successfully ping & SSH with the raspberry pi, even run the program mentioned in the previous point through the SSH and it works fine.
The stack trace:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:358)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2489)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2526)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.climacon.jdbc.db.JDBCMySQLConnection.createConnection(JDBCMySQLConnection.java:42)
at com.climacon.jdbc.db.JDBCMySQLConnection.getConnection(JDBCMySQLConnection.java:51)
at com.climacon.jdbc.main.ClimaConJDBC.get_Nodeinfo_From_DB(ClimaConJDBC.java:110)
at com.climacon.gui.ClimaCon2$5.actionPerformed(ClimaCon2.java:279)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I think the reason you can not access the remote mysql may be due to the remote access restriction in my.cnf
please check the line
bind-address: is set to 127.0.0.1
under this restriction, you can not connect remotely with that mysql server;
to solve this, you need to change this line to:
bind-address: 0.0.0.0
in addition you should specify the port for connection as below:
String URL = "jdbc:mysql://192.168.11.157:3306/DB_name";
because mysql will connect port 3306 in default.
wish my answer could help you!
You have to check the next things:
Is the database active? Does it respond to another application except yours?
Is the network connection OK (eg firewall)?
Check the connection strings (perhaps the port is necessairy but I am not sure).
I am not really familiar with the raspberry. It seems that it's using a linux operating system (correct me if I am wrong). In this post, instruction are given on how to disable firewall on the device. It says that the firewall is the usual iptables firewall used on linux systems. I find this iptables tutorial (based on ubuntu) very useful. Perhaps it would give you some guidance.
Hope I helped!
You may be able to ping the raspberry pi but I am not sure what the interface used is.
Why don't you use MySQL Ping and see if it is responding?
Else it must be a network issue. Get it resolved and then connect. No alternatives for this.
You can issue a light weight ping to your database server to check the connection availability.
Please read following discussion and articles:
Ping MySQL Server
Ping syntax and example
My answer to one of such Communication link failures.
Solved:
Go into the my.cnf file (sudo nano /etc/mysql/my.cnf) file and
look for "bind-address" and make it “bind-address = * “
Reload MySQL config (sudo service mysql reload)
Restart MySQL server (sudo service mysql restart)
The url "jdbc:mysql://localhost:3306/mydb".
You lost the port 3306.
you need to print the exception to the console ,rather than print a customer "error",If you do
as that ,you can't get the key of the problem

Unable to connect to SQL Server 2008 R2 using java connection string

I am not able to connect with SQL server 2008 R2 using java. The same code is working with SQL server 2005.
I have tried to find out the port and ip for the sqlserver service and it is giving me
ip - 0.0.0.0 and port 1434
I tried to use the same connection string that works in SQL Server 2005, but it won't work for me in SQL Server 2008. Here is my connection string:
conn=DriverManager.getConnection(jdbc:sqlserver://127.0.0.1:1434:DatabaseNameconnect?autoReconnect=true,user, password);
This is the Error:
jdbc:sqlserver://127.0.0.1:1434;DatabaseName=connect;user=falcon;Password=admin
Could not connect to database
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.dnb.discovery.connection.ConnectionBean.makeMsSqlConnection(ConnectionBean.java:62)
at com.dnb.discovery.factory.MssqlDAOFactory.<init>(MssqlDAOFactory.java:18)
at com.dnb.discovery.dao.mssqldao.MssqlCompanyDAO.<init>(MssqlCompanyDAO.java:8)
at com.dnb.discovery.relevance.Relevance.modifyRelevanceIndex(Relevance.java:67)
at com.dnb.discovery.relevance.Relevance.calulateRelevanceScore(Relevance.java:36)
at com.dnb.discovery.dao.SolrDAO.readDataFromSolr(SolrDAO.java:222)
at com.dnb.discovery.searchservice.SearchService.buyerTextSearchAnonymous(SearchService.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(Unknown Source)
at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(Unknown Source)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(Unknown Source)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Any help ?
There are many possibilities for your problem:
Firewall
No TCP/IP connector
some services are not running
Try to connect with the SQL-management Studio to you database. If this works, try to connect with SQL-Authentification over TCP/IP.
update
Take a look at the Documentation at http://msdn.microsoft.com/en-en/library/ms143693(v=sql.90).aspx
One obvious problem is that SQL Server listens on port 1433, not 1434. I've already answered this question elsewhere, but I can't be sure if it's an exact match for your problem because you haven't told us what error message you get.

Categories