Java 在openshift上将jdbc连接到MySql服务器时出现问题
所以我在tomcat服务器中使用微软的JDBCJAR连接到openshift上托管的Mysql服务器。 首先是tomcat代码Java 在openshift上将jdbc连接到MySql服务器时出现问题,java,mysql,sql,tomcat,jdbc,Java,Mysql,Sql,Tomcat,Jdbc,所以我在tomcat服务器中使用微软的JDBCJAR连接到openshift上托管的Mysql服务器。 首先是tomcat代码 try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundException e1) { out.println(e1); }
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e1) {
out.println(e1);
}
try {
Connection conn = DriverManager.getConnection("jdbc:sqlserver://xxx.x.xx.x:3306;DatabaseName=encryptionserver", "phpadminuser", "phpadminpass");
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT Username FROM LoggedInUsers WHERE Username='" + user + "'");
String u = "none";
while(rs.next()){
u = rs.getString("Username");
out.println(u);
}
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
out.println("SQL Exception: " + e.toString() + " in getFriendRequest");
}
我正在使用phpMyAdmin凭据来访问openshift中的sql server,所以这可能就是问题所在?它在第二次尝试时失败,并捕获SQLE异常输出
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 1xx.x.xx.x, port 3306 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.". in getFriendRequest
我尝试在本地运行tomcat,在openshift上使用DriverManager.getConnection的服务器ip,并仅使用localhost作为ip来测试它。两者都返回相同的结果。您使用的jdbc驱动程序不正确。对于MySql,您必须使用 另见: