Hello all.
Firstly, i am new to programming java apps that connect to SQL databases.
I have set up a MySQL server on my computer, which i can successfully access through my command prompt on my pc (so i know its up and running). Now im trying to create a simple java program which connects to the sql database, and simply lists the contents of the table in question. However, when running this program i recieve this exception:
java.sql.SQLException: No suitable driver
I have thoroughly researched this problem on the internet, with many people saying that i have not installed the j/connector driver correctly. My j/connecter driver file is in C:\Program Files\JAVASQL\mysql-connector-java-3.0.17-ga-bin.jar . My Environmental Variable CLASSPATH in windows reads: ".;C:\Program Files\Java\jre1.5.0_03\lib\ext\QTJava.zip; C:\Program Files\JAVASQL\mysql-connector-java-3.0.17-ga-bin.jar", so i am pretty sure i have done everything correctly with reguards to installing the connector.
My program code is as follows:
import java.sql.*;
class TestSqlConnect
{
public static void main (String[] args)
{
try
{
Connection sqlConnection = DriverManager.getConnection("jdbc:mysql://127.0.0.1/myDatabaseName","root","mypassword");
Statement sqlStatement = sqlConnection.createStatement();
ResultSet sqlResult = sqlStatement.executeQuery("SELECT * FROM Rooms");
while (sqlResult.next())
{
System.out.println(sqlResult.getString("name"));
}
sqlStatement.close();
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
}
Note i have also tried the url "jdbc:mysql://localhost/myDatabaseName" and still get the same problem.
Any help would be greatly appreciated. cheers.