my application is not connectioning to mysql database
i'm writing a program that needs to connect to a mysql database to retrieve username and password amoung other data, however when i compile and click log in its telling me can't connect to database. here is the code:
Code:
String username = "";
String passWorD = "";
String Year = " ";
try
{
Connection con = DriverManager.getConnection ("jdbc:mysql://localhost/ncu students","mario","computer");
Statement state = null;
state = con.createStatement ();
ResultSet result = state.executeQuery("SELECT user name, password,year FROM student info");
while (result.next())
{
username = result.getString("user name");
passWorD = result.getString("password");
Year = result.getString("year");
}
con.close ();
}
catch (Exception r)
{
System.out.println ("could not connect");
}
JOptionPane.showMessageDialog(null,"user Name: "+username+" password: "+passWorD + " year:"+Year);