Javaプログラムをmysqlデータベースに接続しています。しかし、接続する代わりに例外ブロックが実行されます。つまり、「接続に失敗しました!!」です。
import java.sql.*;
public class Mysqltest
{
public static void main(String args[])
{
String username ="root";
String password ="bharath12";
String url ="jdbc:mysql://localhost:3307/";
String dbName = "sample";
String driver= "com.mysql.jdbc.Driver";
Connection con =null;
try
{
Class.forName(driver).newInstance();
con=DriverManager.getConnection(url+dbName, username, password);
System.out.println("Connection successfully established.");
con.close();
System.out.println("Connection terminated !");
}
catch(Exception e)
{
System.out.println("Connection failed !!");
}
}
}
上記のコードのエラーは何でしょうか?インストール中に故意にmysqlポートを3307に変更しました(したがって、localhost:3307)