JDBC não concta

6 respostas Resolvido
java
T

Caros, estou tentando fazer uma conexão com jdbc há algum tem e não consigo. o erro que aparece é este:

Thu Mar 04 12:03:14 BRT 2021 WARN: Establishing SSL connection without servers identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isnt set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Thu Mar 04 12:03:14 BRT 2021 WARN: Establishing SSL connection without servers identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isnt set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Exception in thread main java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:12)

at br.com.caelum.jdbc.teste.TestaConexao.main(TestaConexao.java:12)

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)

at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)

at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)

at com.mysql.jdbc.Util.getInstance(Util.java:387)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2330)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)

at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:806)

at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)

at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)

at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)

at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:10) 1 more

Caused by: java.lang.NullPointerException: Cannot invoke java.util.Map.get(Object) because this.serverVariables is null

at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:2997)

at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1936)

at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1865)

at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1228)

at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284) 15 more

Alguém pode me dá alguma dica?

6 Respostas

S

O próprio MySQL te deu a dica, veja:

According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set.
For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’.
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Edita sua URL de conexão e adiciona o parâmetro useSSL=false.

T

Continua dando um erro. Você diz, fazer desta maneira:

return DriverManager.getConnection(“jdbc:mysql://localhost:3306/fj21?useSSL=false?”, “root”, “bruno”);

Desta forma eu tenho este erro:

Exception in thread main java.lang.RuntimeException: java.sql.SQLException: The connection property useSSL only accepts values of the form: true’, false’, yes or no’. The value false?’ is not in this set.

at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:12)

at br.com.caelum.jdbc.teste.TestaConexao.main(TestaConexao.java:12)

Caused by: java.sql.SQLException: The connection property useSSL only accepts values of the form: true’, false’, yes or no’. The value false?’ is not in this set.

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)

at com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.validateStringValues(ConnectionPropertiesImpl.java:314)

at com.mysql.jdbc.ConnectionPropertiesImpl$BooleanConnectionProperty.initializeFrom(ConnectionPropertiesImpl.java:91)

at com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom(ConnectionPropertiesImpl.java:216)

at com.mysql.jdbc.ConnectionPropertiesImpl.initializeProperties(ConnectionPropertiesImpl.java:2500)

at com.mysql.jdbc.ConnectionImpl.initializeDriverProperties(ConnectionImpl.java:3196)

at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:790)

at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)

at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)

at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)

at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)

at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:10) 1 more
T

agora baixei o conector mais atual o mysql-connector-java-8.0.23.jar esta conectando mas tenho este erro:

Loading class com.mysql.jdbc.Driver’. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Conexão aberta!

public class ConnectionFactory {
	
	public Connection getConnection(){
		try{
			DriverManager.registerDriver(new com.mysql.jdbc.Driver());
			return DriverManager.getConnection("jdbc:mysql://localhost/fj21", "root", "bruno");
			//return DriverManager.getConnection("jdbc:mysql://localhost:3306/fj21?useSSL=false&zeroDateTimeBehavior=convertToNull", "root", "bruno");
		} catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
}
T
Solucao aceita

Resolvido. Depois de algumas modificações e usando o -> Class.forName(“com.mysql.cj.jdbc.Driver”);

public class ConnectionFactory {

	public Connection getConnection() throws ClassNotFoundException {
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			return DriverManager.getConnection("jdbc:mysql://localhost/fj21", "root", "bruno");
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
}
P

Desta forma tens o chamado erro de falta de atenção… false e false? são duas coisas diferentes…

S

Traduziu a mensagem de erro?
TU só pode usar os valores true, false, yes ou no, mas você usou false? (com uma interrogação atrás).

Criado 4 de março de 2021
Ultima resposta 5 de mar. de 2021
Respostas 6
Participantes 3