我们在使用JDBC连接MySQL数据库的时候,可能会报如下的警告:
我们可能是在写SQL语句的时候或者使用hibernate框架时出现这种警告,解决方法的原理是一样的。如下:
String url = "jdbc:mysql://localhost:3306/Peoples?autoReconnect=true&useSSL=false";
在URL中加上问号后的代码即可。如果使用的是Hibernate框架的话,可以在hibernate.cfg.xml中做如下配置:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory >
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/curricula</property>
<property name="connection.autoReconnect">true</property>
<property name="connection.useSSL">false</property>
<property name="connection.username">root</property>
<property name="connection.password">951993</property><!-- mysql数据库方言 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property> <!-- 在控制台显示sql语句 -->
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property><!-- 是否自动创建表 -->
<!-- <mapping resource="model/Student.hbm.xml"/> -->
<mapping class="model.Student"/>
</session-factory>
</hibernate-configuration>
这是我做案例是的完整配置,亲测可用。