• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection refused: connect

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i'm using hibernate and when i run my app from my pc all goes well;
but when i try to run it from another machine (in a home network), i get this error message:
C:\>java -jar Relatorio.jar
17:43:00,147 WARN SettingsFactory:95 - Could not obtain connection metadata
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net
.ConnectException: Connection refused: connect
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1797)
at com.mysql.jdbc.Connection.<init>(Connection.java:562)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:361)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnec
tion(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.ja
va:72)
at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1
132)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.
java:766)
at relatorio.Assistente.setTudo(Assistente.java:99)
at relatorio.VisualSwing.<init>(VisualSwing.java:59)
at relatorio.Visual.<init>(Visual.java:19)
at relatorio.Visual.main(Visual.java:50)
17:43:03,161 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: 08S01
17:43:03,161 ERROR JDBCExceptionReporter:46 - Unable to connect to any hosts due
to exception: java.net.ConnectException: Connection refused: connect
17:43:03,171 ERROR JDBCExceptionReporter:38 - Cannot open connection
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net
.ConnectException: Connection refused: connect
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1797)
at com.mysql.jdbc.Connection.<init>(Connection.java:562)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:361)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnec
tion(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278
)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3297)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3277)
at net.sf.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.ja
va:40)
at net.sf.hibernate.transaction.JDBCTransactionFactory.beginTransaction(
JDBCTransactionFactory.java:19)
at net.sf.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:2
220)
at relatorio.Assistente.setTudo(Assistente.java:111)
at relatorio.VisualSwing.<init>(VisualSwing.java:59)
at relatorio.Visual.<init>(Visual.java:19)
at relatorio.Visual.main(Visual.java:50)
17:43:04,253 WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: 08S01
17:43:04,253 ERROR JDBCExceptionReporter:46 - Unable to connect to any hosts due
to exception: java.net.ConnectException: Connection refused: connect
17:43:04,263 ERROR JDBCExceptionReporter:38 - Cannot open connection
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net
.ConnectException: Connection refused: connect
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1797)
at com.mysql.jdbc.Connection.<init>(Connection.java:562)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:361)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnec
tion(DriverManagerConnectionProvider.java:101)
at net.sf.hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:278
)
at net.sf.hibernate.impl.SessionImpl.connect(SessionImpl.java:3297)
at net.sf.hibernate.impl.SessionImpl.connection(SessionImpl.java:3277)
at net.sf.hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.j
ava:65)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:704)

at net.sf.hibernate.loader.Loader.doQuery(Loader.java:185)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections
(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1513)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1505)
at relatorio.Assistente.setTudo(Assistente.java:119)
at relatorio.VisualSwing.<init>(VisualSwing.java:59)
at relatorio.Visual.<init>(Visual.java:19)
at relatorio.Visual.main(Visual.java:50)
java.lang.NullPointerException
at relatorio.Assistente.setTudo(Assistente.java:123)
at relatorio.VisualSwing.<init>(VisualSwing.java:59)
at relatorio.Visual.<init>(Visual.java:19)
at relatorio.Visual.main(Visual.java:50)

I changed my hibernate.properties:
hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql:///test
hibernate.connection.username root
hibernate.connection.password ***
in here:
hibernate.connection.username MyMachine'sName,
in order to run it from the other machine

I also made this in MySql:
grant all on *.* to root@192.168.0.123 identified by '***';
192.168.0.123 is my other machine IP
I checked that all jars and other files are included(driver, cfg.xml, log4j and so on...)
Can someone pls help me pls?
Thanks in advance
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CASE SOLVED!
had to do this, in hibernate.properties:
hibernate.connection.url jdbc:mysql://NameOfMyMachine/test
hibernate.connection.username root
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic