试试下面行不行?
import java.sql.*;
public class DBTest { /**
 * @param args
 */
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
try
{
Class.forName("org.gjt.mm.mysql.Driver");
        String url="jdbc:mysql://localhost:3306/test";
        Connection conn=null;
        conn=DriverManager.getConnection(url,"root","123");
        if(conn!=null)
         System.out.println("Connection sucess!");
}
catch(SQLException e )
{
System.out.println(e.getMessage());
}
catch(Exception e )
{
System.out.println(e.getMessage());
} }}

解决方案 »

  1.   

    运行以上的代码好是报的Communication link failure: java.io.IOException, underlying cause: Unexpected end of input stream
    现在关键是不知道问题出在哪上面,连接字符串的格式应该是正确的
    不知道还有哪位高手能解答一下
      

  2.   

    不知道你的连接驱动是哪一个,因为下载不同的驱动,class.forname("")这里是不一样的