Answer the question
In order to leave comments, you need to log in
Why is MySql database not working in Maven?
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionDateBase {
public static final String DB_URL = "jdbc:mysql://localhost:3306/chat";
public static final String H2_DRIVER = "com.mysql.jdbc.Driver";
public static final String LOGIN = "root";
public static final String PASSWORD = "app112";
public ConnectionDateBase() {
}
public Connection getConnection() throws SQLException, ClassNotFoundException {
Class.forName(H2_DRIVER);
return DriverManager.getConnection(DB_URL, LOGIN, PASSWORD);
}
}
Answer the question
In order to leave comments, you need to log in
https://yadi.sk/d/sqycbG9SuN7NC
Launched, the only error is that it cannot reach the sql server, since it does not exist
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
private static final String URL = "jdbc:mysql://localhost:3306/testsql?useUnicode=true&useSSL=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.5.0</version>
<configuration>
<mainClass>mainFx.Main</mainClass>
</configuration>
</plugin>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.3</version>
</dependency>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question