Hi all,
I have tried to use the following codes to connect to my mySQL database and the results given is always "Cannot connect to server". May I know what is wrong? Or is there anything which I shld add before I compile n run the codes below?
I can confirm the password and username are correct.
TIA....
import java.sql.*;
public class Connect
{
public static void main (String []args)
{
Connection conn = null;
String url = "jdbc:mysql://localhost/vpg";
String userName = "root";
String password = "root";
try
{
Class.forName("com.mysql,jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Connected");
}
catch (Exception e)
{
System.err.println ("Cannot connect to server.");
}
finally
{
if (conn!=null)
{
try {
conn.close();
System.out.println ("Disconnected.");
}
catch (Exception e) {}
}
}
}
}
I have tried to use the following codes to connect to my mySQL database and the results given is always "Cannot connect to server". May I know what is wrong? Or is there anything which I shld add before I compile n run the codes below?
I can confirm the password and username are correct.
TIA....
import java.sql.*;
public class Connect
{
public static void main (String []args)
{
Connection conn = null;
String url = "jdbc:mysql://localhost/vpg";
String userName = "root";
String password = "root";
try
{
Class.forName("com.mysql,jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);
System.out.println("Connected");
}
catch (Exception e)
{
System.err.println ("Cannot connect to server.");
}
finally
{
if (conn!=null)
{
try {
conn.close();
System.out.println ("Disconnected.");
}
catch (Exception e) {}
}
}
}
}