1

MySQL JDBC ライブラリを eclipse プロジェクトに追加しましたが、それでもデータベースに接続できません。プログラムはエラーをスローせず、フリーズするだけです。私が使用したライブラリへのリンクは次のとおりですhttp://dev.mysql.com/downloads/connector/jと現在のコード(ユーザー名、ホスト、およびパスワードは省略されています。

  private Connection connect = null;
  private Statement statement = null;
  private PreparedStatement preparedStatement = null;
  private ResultSet resultSet = null;

@Override
    try {
          // This will load the MySQL driver, each DB has its own driver
          Class.forName("com.mysql.jdbc.Driver");
          // Setup the connection with the DB
          connect = DriverManager
              .getConnection("jdbc:mysql://host:8080/feedback?"
                  + "user=******Admin&password=********");

          // Statements allow to issue SQL queries to the database
          statement = connect.createStatement();
          // Result set get the result of the SQL query
          System.out.println("Connected");
        } catch (Exception e) {
          System.out.println("Connection failed");

解決策 ポートが間違っていて、ドライバーが正しくインストールされておらず、データベース名が間違っていました。ドライバーを修正した後の正しい接続線は次のとおりです。

 connect = DriverManager
                  .getConnection("jdbc:mysql://localhost:3306/DataBase?"
                      + "user=****Admin&password=*******");
4

2 に答える 2