Spring学习1

直接学习springboot发现有些困难,还是按部就班从spring开始。这里总结一些问题。课程中老师为了解释什么是耦合使用了jdbc。

一、数据库无法连接

之前使用Navicat连接的数据库无法连接,去“服务器”查看数据库没问题,突然想到了看看连接的IP,ifconfig 果然IP变了,前几天实验室重新进行了网络规划,之前的ip变了,重连即可;

二、Launch Error

程序写好,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.gsynf.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
* @ClassName: JdbcDemo1
* @Description: Jdbc的使用,目的为了理解什么是耦合
* @author: gsynf
* @date: 2019年10月25日 下午9:18:27
*/
public class JdbcDemo1 {

/**
create table account(
id int primary key auto_increment,
name varchar(20),
money float
);
* @Title: main
* @Description: TODO
* @param args
* @return: void
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
// 1.注册驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
// 2.获取连接
Connection conn = DriverManager.getConnection("jdbc:mysql://IP地址:3306/spring5","账户","密码");
// 3.获取操作数据库的预处理对象
PreparedStatement pstm = conn.prepareStatement("select * from account");
// 4.执行SQL语句(如果有结果集,得到结果集)
ResultSet rs = pstm.executeQuery();
// 5.遍历结果集。封装
while(rs.next()) {
System.out.println(rs.getString("name")+","+rs.getFloat("money"));
}
// 6.释放资源
rs.close();
pstm.close();
conn.close();
}

}

正常编译,莫名其妙的弹出Launch Error,应该是JVM无法启动,百度谷歌了一圈也没找着,重新建了一个工程,建了一个类直接编译也还是一样,最后发现是JRE和JDK的版本不相应的问题,新建项目时,我的JRE选择的是本机安装的默认的11

此时,下方会弹出一个警告

大致意思是现在选择的JRE是11版本,但是默认的JDK是12版本,不匹配,点击Configure将JDK也选择为11即可。

三、SSL警告

使用mysql-jdbc连接MySQL出现如下警告 :

1
Establishing SSL connection without server's identityverification 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 optionisn't set. For compliance with existing applications not using SSL theverifyServerCertificate property is set to 'false'. You need either toexplicitly disable SSL by setting useSSL=false, or set useSSL=true and providetruststore for server certificate verification.

原因是MySQL在高版本需要指明是否进行SSL连接。解决方案如下:

在mysql连接字符串url中加入ssl=true或者false即可,如下所示:

1
Connection conn = DriverManager.getConnection("jdbc:mysql://IP地址:3306/spring5?useSSL=false","账户","密码");

四、Spring配置文件中提示的配置

复制路径:

* http://www.springframework.org/schema/beans/spring-beans.xsd

另存为xsd格式,esclipse中Windows-Preference,查找XML Catalog,选择User Specified Entries,添加刚才下载的xsd文件,spring中的xml文件选择以Spring Config Enditor打开即可。

:转载文章请注明出处,谢谢~