Spring入门
数据库配置问题
pom.xml中的配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.itspring</groupId> <artifactId>day01_eesy_01jdbc</artifactId> <version>1.0-SNAPSHOT</version> 以下为配置内容 <packaging>jar</packaging> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connecter-java</artifactId> <version>8.0.19</version> </dependency> </dependencies> </project>
由于mysql版本过高,导入的时候需要这样写
//注册驱动 DriverManager.registerDriver(new com.mysql.jdbc.Driver()); //获取连接,mysql版本高报错The server time zone,需要这样写 Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/eesy?serverTimezone=UTC","root", "ltx123456"); //获取数据库的预处理对象 PreparedStatement pstm=conn.prepareStatement("select * from account"); //执行sql得到结果类 ResultSet rs=pstm.executeQuery(); //遍历结果集 while(rs.next()){ System.out.println(rs.getString("name")); } //释放资源 rs.close(); pstm.close(); conn.close();