java连接MySQL失败!急救!!
import java.sql.*;
public class TestJdbc
{
public Connection con;
public TestJdbc()
{
}
public Connection connect()
{
String url ="jdbc:mysql://localhost/sql_test";
String user="root";
String password="123456";
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
try
{
con=DriverManager.getConnection(url,user,password);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
return con;
}
public static void main(String args[]){
TestJdbc tm=new TestJdbc();
Connection m=tm.connect();
if(m!=null){
System.out.println("成功!");
}
}
}
出现了如下的异常:
MESSAGE: java.net.ConnectionException: Connection refused: connect
STACKTRACE:
java.net.SocketException:java.net.ConnectException: Connection refused: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
at com.mysql.jdbc.MyselIO.<init><MysqlIO.java:284>
.......
请问这是怎么回事,怎么解决呢,请帮帮我啊,小弟跪求了!!!