• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Java JDCB "no suitable driver found" problem

Status
Not open for further replies.

christiandb

Member
Joined
Feb 5, 2008
Messages
2,469
Reaction score
5
Location
010
Here is my code:
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?
 
Fixed it, had to add the jar file to my libraries and had to change:
Code:
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
to:
Code:
            Class.forName("com.mysql.jdbc.Driver");
 
Status
Not open for further replies.
Back
Top