christiandb
Member
Here is my code:
But I'm getting the following error:
Does anyone know the solution for that?
Code:
import java.sql.*;
public class test
{
static Connection con;
static Statement stmt;
public static void main(String[] args)
{
insertAccount();
}
public static Connection getConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/bank", "root", "pass");
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
return con;
}
public static void insertAccount()
{
Connection con = getConnection();
String newaccount = "INSERT INTO accounts VALUES (null, den Boer, 0)";
try
{
stmt = con.createStatement();
stmt.executeUpdate(newaccount);
stmt.close();
con.close();
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
System.out.println("Account created succesfully");
}
}
But I'm getting the following error:
Code:
SQLException: No suitable driver found for jdbc:mysql://localhost:3306/bank
Does anyone know the solution for that?