1.1 以你喜欢的方式(思惟导图或其余)概括总结多数据库相关内容。
mysql
Q1. MySQL数据库基本操做
创建数据库,将本身的姓名、学号做为一条记录插入。(截图,需出现本身的学号、姓名)
在本身创建的数据库上执行常见SQL语句(截图)
-参考:实验任务书-题目1sql
一、创建数据库语句:
二、数据库创建成功:
三、添加学生信息语句:
四、查询学生信息语句:
数据库
Q2. 使用JDBC链接数据库与Statement安全
2.1 使用Statement操做数据库。(粘贴一段你认为比较有价值的代码,出现学号)学习
使用Statement操做数据库,展示数据库中学生的id/stuno/birthdate信息,以下图:
url
2.2 使用JDBC操做数据库主要包含哪几个步骤?
-参考:实验任务书-题目2code
一、安装驱动;
二、创建链接、connection;
三、statement语句;
四、RresultSet结果集;
五、Release关闭释放资源。orm
Q3. PreparedStatement与参数化查询
参考:实验任务书-题目3
3.1 使用PreparedStatement根据用户指定的查询条件进行查询。(粘贴一段你认为比较有价值的代码,出现学号)blog
//201521123074 Connection con = null; PreparedStatement pStatement = null; ResultSet rs = null; SimpleDateFormat hmFromat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GBK"; String userName = "root"; String password = "gsjy1998041"; try { con = DriverManager.getConnection(url, userName, password); String strSql = "select * from students where name = ?"; pStatement = con.prepareStatement(strSql); pStatement.setString(1,name); rs = pStatement.executeQuery(); while (rs.next()) { System.out.println(rs.getString("stuno") + "\t"); System.out.println(rs.getString("name") + "\t"); System.out.println(rs.getString("gender") + "\t"); System.out.println(rs.getInt("age") + "\t"); System.out.println(rs.getDate("birthdate") + "\t"); System.out.println(rs.getString("major") + "\t"); } pStatement.close();
3.2 批量更新-批量插入1000个学生,统计整个操做所消耗的时间。(使用方法executeBatch)
。资源
啊。。这题总是会出现这样的错误T _T运行不了因此测不了时间。。。
Q4. JDBCUtil与DAO
参考:实验任务书-题目5
4.1 粘贴一段你认为比较有价值的代码,出现学号
public class JDBCUtil { //201521123074 private static String driverName = "com.mysql.jdbc.Driver";// jdbc4.0之后不须要 private static String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GBK"; private static String userName = "root"; private static String password = "123456"; public static void registerDriver() { try { Class.forName(driverName);// jdbc4.0之前须要这句进行驱动注册 } catch (ClassNotFoundException e) { e.printStackTrace(); System.out.println("找不到驱动"); } } public static Connection getConnection() throws SQLException { Connection conn = null; System.out.println("正在链接数据库..."); conn = DriverManager.getConnection(url, userName, password); System.out.println("数据库已链接!"); return conn; } public static void closeConnection(Connection conn) { System.out.println("正在释放全部资源..."); if (conn != null) { try { conn.close(); conn = null; } catch (SQLException e) { e.printStackTrace(); } } } /* * 释放全部资源 */ public static void realeaseAll(ResultSet rs,Statement st,Connection conn){ if(rs!=null){ try { rs.close(); rs = null; } catch (SQLException e) { e.printStackTrace(); } } if (st!=null){ try { st.close(); st = null; } catch (SQLException e) { e.printStackTrace(); } } closeConnection(conn); }
4.2 使用DAO模式访问数据库有什么好处?
各个层的代码分开写,思路要清晰些,并且方便维护.DAO存在大部分是为了理清思路,代码简洁易懂。
Q5. 使用数据库改造购物车系统
5.1 使用数据库改造之前的购物车系统(应有图形界面)。若是之前为完成购物车系统,可编写基于数据库的学生管理系统。包括对学生的增删改查,要求使用。
5.2 相比较使用文件,使用数据库存储与管理数据有何不同?
文件储存比较方便管理,但是安全性很低;数据库存储比较复杂点,安全性高。
3.1. 码云代码提交记录
在码云的项目中,依次选择“统计-Commits历史-设置时间段”, 而后搜索并截图