I have not worked with databases before and wanted to practice with video tutorials, but I immediately get an error.
this is my code: (with database i work in netbeans)
`
package javaapplicationdatabase;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
public class JavaApplicationDataBase {
public static final String DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
public static final String CONN_STRING = "jdbs:mysql://localhost:3306/?user=root&password=root";
public static void main(String[] args) {
Enumeration<Driver> drivers = DriverManager.getDrivers();
while(drivers.hasMoreElements())
System.out.println(drivers.nextElement());
try {
Class.forName(DRIVER_NAME);
} catch (ClassNotFoundException ex) {
System.out.println("MySQL driver not found!");
return;
}
try {
Connection conn = DriverManager.getConnection(CONN_STRING);
} catch (SQLException ex) {
System.out.println("Cannot open connection!" ex.getMessage());
return;
}
}
}
`
in libraries of this project i connected mysql-connected. connect mysql connected in netbeans project
I tried to reinstall mysql and write the path to the driver in a different way, but it still gives this error. I read answers to other questions about this error and they all say that you need to connect the jar file, but i have it connected and i don’t know how else to solve the problem.
CodePudding user response:
In my opinion it is can be typo in your url, try change:
jdbs:mysql:
to
jdbc:mysql:
CodePudding user response:
just add the MySQL JDBC JAR into class path if you are running on Java SE6 and driver is JBC 4.0 compliant, e.g. mysql-connector-java-5.1.36-bin.jar.