我在握手期间收到错误通信失败。localhost:3306 上是否有服务器运行?我已经使用类型 4 jdbc 驱动程序编写了一个 jdbc 程序,我想执行删除操作,ide 是 eclipse。代码:
Class.forName("com.mysql.jdbc.Driver");
String cs="jdbc:mysql://localhost:3306/account_db";
Connection con=DriverManager.getConnection(cs,"root",<password>);
PreparedStatement ps=con.prepareStatement("delete from empde emp_id=?");
Scanner s=new Scanner(System.in);
while(true)
{
System.out.println("enter the emp_id :");
int ac_id=s.nextInt();
ps.setInt(1,emp_id);
ps.executeUpdate();
System.out.println("one emp_id is deleted:");
System.out.println("one more emp_id?(yes/no)");
String choice=s.next();
if(choice.equals("no"))
System.out.println("empde is exit");
break;
}
ps.close();
con.close();
检测到错误:
java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3306? at com.mysql.jdbc.MysqlIO.init(Unknown Source)