So, I'm trying to get the variable Weekly Sales from a SQL table, and then add the amounts to a total amount. That being said, I can't seem to be able to connect and I get an error. The error is "No suitable driver found for jdbc:mysql://128.198.162.204/INFS3070" even though I believe I have everything that I need, and everything looks correct to me.
Here's my code for the part I'm stuck on.
import java.sql.*;
public class FileConnection
{
public static void main(String[] args)
{
try
{
// Create variables for database connection parameters
String url = "jdbc:mysql://128.198.162.204/INFS3070";
String user = "infsclass";
String password = "webclass";
Connection conn = null;
Statement sqlQuery = null;
ResultSet results = null;
// Connect to database using variables
conn = DriverManager.getConnection(url, user, password); // Different to separate connection file
// Simply for esthetic purposes
System.out.println("Connection to database created.");
System.out.println("------------------------------------------------------");
// Create object to execute SQL statements
sqlQuery = conn.createStatement();
// Use a String to send the SQL statement to the database
results = sqlQuery.executeQuery("SELECT SUM FROM SALES");
// Display results in console
// We use a while loop to read all of the data
while (results.next())
{
// Formatting the console output to appear as a table.
System.out.printf("%s, %-15s %-15s %-15s %-15s %s\n", // Formats how the printf data will align
results.getString("PK"),
results.getString("Store"),
results.getString("Dept"),
results.getString("SalesDate"),
results.getString("Weekly_Sales"),
results.getString("IsHoliday"));
}
// Close database connection
conn.close();
System.out.println("-----------------------------------------------------");
System.out.println("Connection to database closed.");
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
Also, here's the SQL table