0

I'm trying to insert values into an existing java DB running on my local machine. My code:

    void insertVal(String json){
    Connection conn = null;
    //DriverManager.registerDriver(new com.mysql.jdbc.Driver ());jdbc:mysql://localhost:3306/?user=root
    try {
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Orders", "root", "1234");
        Statement st = conn.createStatement();

        String insert = "INSERT INTO orders " +  json;

        st.executeUpdate(insert);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

It keeps saying java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/?user=root I've added the JDBC driver given here Connect Java to a MySQL database (used independent platform) and added it as a dependency using Intellij. What am I missing? Thanks!

EDIT: To anyone encountering this issue, this code is fine. my driver version wasn't the most updated one.

Omri. B
  • 375
  • 1
  • 13
  • Unfortunately no – Omri. B Apr 21 '21 at 17:29
  • Why not? and what did you try to find the solution to this question? Please [edit] your question and add more relevant info to it. – Luuk Apr 21 '21 at 17:29
  • That user had an issue with his URL, I copied mine directly from the workbench. Regarding the path, I've added the tar.gz driver file into the module dependencies. Nearly all questions regarding to this topic were solved by the path, something I believe I did correctly – Omri. B Apr 21 '21 at 17:32

1 Answers1

1

You need to create a new user, for some reason the root user does not work on the MAC