1

I am creating a JavaFX application with IntelliJ and I am trying to add data to a MySQL DB. The problem I am getting is No Suitable driver found.

I have created a datasource within IntelliJ with the following settings: datasource settings Driver settings

I have tried other ways as specified in other threads, but still get the same issue.

The Code I am running to establish the connection and run a statement is as follows:

public void connectToDB() throws SQLException{
    String host = "jdbc:mysql://localhost:3306/librarycollection";
    Connection con = DriverManager.getConnection(host,"root","password");
    PreparedStatement statement  = con.prepareStatement("INSERT INTO user_table VALUE ?,?,?,?,?");
    statement.setString(1,firstName_field.getText());
    statement.setString(2,lastName_field.getText());
    statement.setString(3,username_field.getText());
    statement.setString(4,email_field.getText());
    statement.setString(5,registerPasswordConfirm_field.getText());
    statement.execute();
}

Am I missing code within my method or is this something to do with the configuration?

This is not a duplicate as it may refer to the configuration of JavaFX, I have a driver installed and server running as a process. I am able to connect through intellij's 'Test Connection' with all the parameters and it comes back successful.

The code I have is the same as all other threads and is not required to put Class.forName() etc. as this is included in the Driver 4.0 (which I am using).

ArcherGilly
  • 149
  • 11
  • I don't code in Intellij so wondering, you don't have to include driver in your project? As I code in Netbeans and always have driver's dependency in Maven's pom.xml – Mykola Aug 18 '17 at 16:36
  • Also, it very very unlikely that the port 3306 might cause you an issue since you're not even getting driver trying to connect to your local DB server, but if you get further trouble with connection, try to remove port – Mykola Aug 18 '17 at 16:38
  • I have tested the connection through Intellij's datasource wizard and it was successful, intellij wizard downloads the required drivers if it see's its missing. That's where the second Image comes from. – ArcherGilly Aug 18 '17 at 16:46
  • The fact your IDE installed the driver for use inside the IDE tooling, does not mean that it is available to your project. You need to explicitly add a dependency to the driver in your project. – Mark Rotteveel Aug 18 '17 at 17:07
  • @MarkRotteveel I understand this, but if the .jar files are showing within the projects class path, isn't this explicitly adding this as a dependency? – ArcherGilly Aug 19 '17 at 11:14
  • Given there is nothing called "projects class path" in IntelliJ, I have to assume: no. You really need to show exactly what you configured, and how you are running your application when this error occurs. – Mark Rotteveel Aug 19 '17 at 11:20
  • thank you.. I have solved this, even though I had the Sqljdbc.jars, I had to import the connection/J jars seperatley. – ArcherGilly Aug 19 '17 at 12:00

0 Answers0