0

So I'm using microsoft's jdbc jar in my tomcat server to connect to a Mysql server hosted on openshift. Firstly here's the tomcat code...

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");
            } 

I'm using phpMyAdmin credentials that I use to access the sql server in openshift, so perhaps that's the issue? It fails at the second try and it catches the SQLException e outputting

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 

I've tried testing it by running tomcat locally, on openshift using the server ip for the DriverManager.getConnection and just using localhost as the ip. Both give back the same result.

Francisco
  • 10,918
  • 6
  • 34
  • 45
Man Person
  • 1,122
  • 8
  • 20
  • 34
  • does [this](http://stackoverflow.com/questions/24592717/error-connection-refused-connect-verify-the-connection-properties) or [this](http://stackoverflow.com/questions/18841744/jdbc-connection-failed-error-tcp-ip-connection-to-host-failed) helps you – Ankur Singhal Nov 27 '14 at 02:00

1 Answers1

1

You are using an incorrect jdbc driver. For MySql you must use com.mysql.jdbc.Driver class provided by MySQL Connector/J

See also:

Federico Sierra
  • 5,118
  • 2
  • 23
  • 36