com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 错误怎么解决
我用的一个简单的测试MySql数据库JDBC连接是否成功,程序没有错误,但打开网页时会出现:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago。不知道这是为什么,请高手们帮帮忙,万分感谢。我是个新手,希望大家多多指教。
我的程序如下:
<%@page contentType="text/html;charset=gb2312"%>
<DOCTYPE html>
<%java.sql.Connection conn=null;
java.lang.String strConn;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=java.sql.DriverManager.getConnection("jdbc:mysql://locasthost/test","root","wjyzzdx");
%>
//连接Mysql数据库成功
<%
}catch(java.sql.SQLException e){
out.print(e.toString());
}finally{
if(conn!=null) conn.close();
}
%>