Search code examples
javamysqljdbcjavadb

WARNING: ConnectionID:1 Prelogin error: host 127.0.0.1 port 3306 Unexpected response type:74


Right now I am trying to make a simple DBConnection using Java. I am using the Eclipse IDE for the development.

import java.sql.*;


public class DbConnect {
    private static String url = "jdbc:sqlserver://127.0.0.1:3306;databaseName=personal_AkiraDatabase";
    private static String user = "XXXX";
    private static String password = "XXXX";

    public static void main(String [] Args){
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = DriverManager.getConnection(url, user, password);
            if(con != null){
                System.out.println("Connection was a success!");
            }else{
                System.out.println("Connection failed. :(");
            }


        } catch (ClassNotFoundException e) {
                e.printStackTrace();
                System.out.println("ClassNotFoundException :(");
            } catch (SQLException e) {
                e.printStackTrace();
                System.out.println("SQLException :(");
            }
        }

}

But currently it gives me this Error Message.

Jul 05, 2014 7:20:15 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin WARNING: ConnectionID:1 Prelogin error: host 127.0.0.1 port 3306 Unexpected response type:74

I'm not even sure if it is a program problem, cause it was not an exception. The message just pops up in the console over and over again like as if it was in a loop.

I have tried:

  • Googling up to 3 pages, other people's problems were a lot different than mine.
  • Turning off all my Firewalls.
  • netstat -an on CMD. 127.0.0.1:3306 is established.
  • Crying like a wee baby

Currently:

  • I have the DB on my local drive and I have a DB Named above. I actually have 1 test table on it.
  • It does that error message with my Root password, with a admin user password and a random credential that is not in the user list of the database.
  • I run my DB with MySQL Workbench

Possibly:

  • I need to host my DB on something like XAMPP locally? Cause having it on MySqlServer is not enough?
  • I just need to cry myself to sleep?

Thanks, And I am mostly online to answer for any vague details.

Here is a list of my LocalHost via netstat

    TCP    127.0.0.1:3306         127.0.0.1:7303         ESTABLISHED
TCP    127.0.0.1:3306         127.0.0.1:11990        ESTABLISHED
TCP    127.0.0.1:3306         127.0.0.1:11991        ESTABLISHED
TCP    127.0.0.1:3306         127.0.0.1:11999        ESTABLISHED
TCP    127.0.0.1:7303         127.0.0.1:3306         ESTABLISHED
TCP    127.0.0.1:10000        0.0.0.0:0              LISTENING
TCP    127.0.0.1:11990        127.0.0.1:3306         ESTABLISHED
TCP    127.0.0.1:11991        127.0.0.1:3306         ESTABLISHED
TCP    127.0.0.1:11999        127.0.0.1:3306         ESTABLISHED
TCP    127.0.0.1:12025        0.0.0.0:0              LISTENING
TCP    127.0.0.1:12110        0.0.0.0:0              LISTENING
TCP    127.0.0.1:12119        0.0.0.0:0              LISTENING
TCP    127.0.0.1:12143        0.0.0.0:0              LISTENING
TCP    127.0.0.1:12465        0.0.0.0:0              LISTENING
TCP    127.0.0.1:12563        0.0.0.0:0              LISTENING
TCP    127.0.0.1:12993        0.0.0.0:0              LISTENING
TCP    127.0.0.1:12995        0.0.0.0:0              LISTENING
TCP    127.0.0.1:27275        0.0.0.0:0              LISTENING

Solution

  • You are using Mysql as DB and trying to connect to SQLSERVER DB in your code. That is wrong.

    An example database connection between Java and Mysql looks likes below:

    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String url = "jdbc:mysql://localhost:3306/personal_AkiraDatabase";
    String username = "xxxx";
    String password = "xxxxx"
    Connection connection = null;
    try {
        System.out.println("Connecting database...");
        connection = DriverManager.getConnection(url, username, password);
        System.out.println("Database connected!");
    } catch (SQLException e) {
        throw new RuntimeException("Cannot connect the database!", e);
    } finally {
        System.out.println("Closing the connection.");
        if (connection != null) try { connection.close(); } catch (SQLException ignore) {}
    }
    

    From : Connect Java to a MySQL database