栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

mysql 没有到主机的路由

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mysql 没有到主机的路由

I am trying to deploy my Jersey project from eclipse on openshift and I am getting this error in the tail files Caused by: java.net.NoRouteToHostException: No route to host

before when I had like this:

String host = "jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/bustrackerserver"

I got this error:

'java.lang.NumberFormatException: For input string: “OPENSHIFT_MYSQL_DB_PORT”'

I have pinged this ip address 127.10.230.440 and I am getting response

I checked whether some of the port 8080, 3306 are being used from my local mashine but they are just being used from eclipse.

Apple class.

package org.busTracker.serverSide;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.util.Map;

import javax.ws.rs.GET;

import javax.ws.rs.Path;

import javax.ws.rs.Produces;

import javax.ws.rs.core.MediaType;

@Path("myresource")

public class Apple {

//String host = " jdbc:mysql://${env.OPENSHIFT_MYSQL_DB_HOST}:${env.OPENSHIFT_MYSQL_DB_PORT}/serv‌​erside";

//String host = "jdbc:mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/bustrackerserver";

String host = "jdbc:mysql://127.10.230.440:3306/bustrackerserver";

String user = "adminNMccsBr";

String password = "K3SV5rbxh8qP";

@GET

@Produces(MediaType.TEXT_PLAIN)

public String getIt() {

Connection conn = null;

try {

Class.forName("com.mysql.jdbc.Driver");

System.out.println("Connecting to database…");

conn = DriverManager.getConnection(host,user,password);

Map env = System.getenv();

for (String envName : env.keySet()) {

System.out.format("%s=%s%n",

envName,

env.get(envName));

}

} catch (Exception e) {

e.printStackTrace();

} finally {

if (conn != null) {

try {

conn.close();

} catch (SQLException e) {

// ignore

}

}

}

return "Hello, from apple class 14.05.15 13:30!";

}

}

解决方案

Your MySQL is not listening on TCP/IP and hence your attempt to connect is failing. You sort of answered your question when you said:

I checked whether some of the port 8080, 3306 are being used from my local mashine but they are just being used from eclipse.

In other words, MySQL is not listening on localhost. To confirm this another way, try connecting to MySQL from the command prompt:

mysql -u adminNMccsBr -h 127.10.230.440 -p YOUR_DB_NAME

I expect this to fail. The solution to your problem is to configure MySQL to listen on localhost. In the /etc/my.cnf config file, under the [mysqld] line, add the following:

bind-address = 127.10.230.440

This is not a Java problem, it's a MySQL problem.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/955454.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号