1.下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB,导入world.sql,提交导入成功截图
2.编写程序,查询世界上超过“你学号前边七位并把最后一位家到最高位,最高位为0时置1”(比如学号20165201,超过3016520;学号20165208,超过1016520)的所有城市列表,提交运行结果截图
3.编写程序,查询世界上的所有中东国家的总人口
4.编写程序,查询世界上的平均寿命最长和最短的国家
相关问题

GetDBConnection类由于系统版本不同,经过网上搜索改为

  • task1
  • @author Fomalhaut20175201
  • @date 2019/5/4
    /
    import java.sql.
    ;
    public class GetDBConnection {
    public static Connection connectDB(String DBName,String id,String p) {
    Connection con = null;
    String
    uri = "jdbc:mysql://localhost:3306/"+DBName+"?serverTimezone=GMT%2B8&characterEncoding=utf-8";
    try{ Class.forName("com.mysql.cj.jdbc.Driver");//加载JDBC-MySQL驱动
    }
    catch(Exception e){}
    try{
    con = DriverManager.getConnection(uri,id,p); //连接代码
    }
    catch(SQLException e){}
    return con;
    }
    }

相关步骤
一、world.sql

1.下载相关附件并解压。
2.在数据库单击右键,运行sql文件,选择sql文件,点击开始。
3.导入完成后,重新打开连接会有显示。
二、编写程序,查询世界上超过“你学号前边七位并把最后一位家到最高位,最高位为0时置1”

1.学号为20175214 查询为超过3017520
2.实验代码

  • task1
  • @author Fomalhaut20175201
  • @date 2019/5/4
    */

import java.sql.;
public class task1 {
public static void main(String[] args) {
Connection con;
Statement sql;
ResultSet rs;
con = GetDBConnection.connectDB("world","root","123");
if(con == null) {
return;
}
try {
sql=con.createStatement();
rs = sql.executeQuery("SELECT
FROM city");
while (rs.next()) {
int ID = rs.getInt(1);
String Name = rs.getString(2);
String CountryCode = rs.getString(3);
String District = rs.getString(4);
int Population =rs.getInt(5);
if(Population>6017520) {
System.out.printf("%d\t", ID);
System.out.printf("%s\t", Name);
System.out.printf("%s\t", CountryCode);
System.out.printf("%s\t", District);
System.out.printf("%d\n", Population);
}
}
con.close();
}
catch (SQLException e) {
System.out.println(e);
}
}
}

3.相关截图

三、编写程序,查询世界上的所有中东国家的总人口

1.相关代码

  • task2
  • @author 20175201
  • @date 2019/5/4
    */

import java.sql.;
public class task2 {
public static void main(String[] args) {
Connection con;
Statement sql;
ResultSet rs;
con = GetDBConnection.connectDB("world","root","123");
if(con == null) return;
String sqlStr = "select
from country where Region = 'Middle East'";
try {
sql = con.createStatement();
rs = sql.executeQuery(sqlStr);
long totalpopulation = 0;
while(rs.next()) {
int Population = rs.getInt(7);
totalpopulation +=Population;
}
System.out.println("中东国家的总人口为"+totalpopulation);
con.close();
}
catch (SQLException e) {
System.out.println(e);
}
}
}

2.截图
四、编写程序,查询世界上的平均寿命最长和最短的国家

1.相关代码

  • task2
  • @author 20175201
  • @date 2019/5/4
    /
    import java.sql.
    ;
    public class task3 {
    public static void main(String[] args) {
    Connection con;
    Statement sql;
    ResultSet rs;
    con = GetDBConnection.connectDB("world","root","123");
    if(con == null) {
    return;
    }
    String sqlStr = "select * from country order by LifeExpectancy";
    try {
    sql = con.createStatement();
    rs = sql.executeQuery(sqlStr);
    rs.first();
    String highcountry,lowcountry;
    float number1 = rs.getInt(8);
    while(number1 == 0) {
    rs.next();
    number1 = rs.getInt(8);
    }
    lowcountry = rs.getString(2);
    System.out.println("世界上平均寿命最短的国家为:"+lowcountry+" 寿命为"+number1);
    rs.last();
    float number2 = rs.getInt(8);
    highcountry = rs.getString(2);
    System.out.println("世界上平均寿命最长的国家为:"+highcountry+" 寿命为"+number2);
    con.close();
    }
    catch (SQLException e) {
    System.out.println(e);
    }
    }
    }

2.截图

线下作业MySQL #20175201的更多相关文章

  1. 20175234 数据库MySQL(课下作业)

    20175234 数据库MySQL(课下作业) 内容: 1.下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SE ...

  2. 数据库MySQL(课下作业,必做)

    数据库MySQL(课下作业,必做) 题目要求: 下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB,导入 ...

  3. 20175221 曾祥杰 数据库MySQL(课下作业,必做)

    数据库MySQL(课下作业,必做) 题目要求: 1. 下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB ...

  4. 20175314薛勐 数据库MySQL(课下作业,必做)

    数据库MySQL(课下作业,必做) 要求 下载附件中的world.sql.zip, 参考Intellj IDEA 简易教程:数据库,导入world.sql,提交导入成功截图 编写程序,查询世界上超过& ...

  5. MySQL数据库的优化(下)MySQL数据库的高可用架构方案

    MySQL数据库的优化(下)MySQL数据库的高可用架构方案 2011-03-09 08:53 抚琴煮酒 51CTO 字号:T | T 在上一篇MySQL数据库的优化中,我们跟随笔者学习了单机MySQ ...

  6. Centos下安装mysql 总结

    一.MySQL安装 Centos下安装mysql 请点开:http://www.centoscn.com/CentosServer/sql/2013/0817/1285.html 二.MySQL的几个 ...

  7. .NET Core 成都线下面基会拉开序幕

    2017年07月29日下午,由 .NET China Foundation 成都小组组织的 .NET Core 成都地区线下技术交流会在成都成华区某茶楼成功举行,这也是成都地区 .NET Core 非 ...

  8. 【广州.NET社区线下活动】云定未来 - Azure Meetup

    第2届 广州.NET线下沙龙 Azure Meetup 4月13日,第2届广州.NET线下沙龙在广州银行大厦7楼中创学院路演大厅成功举办.来自微软MVP.网易的技术专家们带来了干货满满的知识分享,即使 ...

  9. CTF线下防御战 — 让你的靶机变成“铜墙铁壁”

    本文首发安全客,未经允许禁止转载.原文链接 一. 前言 随着CTF的普及,比赛的形式也有了越来越多的花样,对于线下赛来说,开始出现了安全加固或者防御战之类的环节,亦或者因为拿下靶机后不希望其他攻击者进 ...

随机推荐

  1. 编号001:deque用法暂时总结

    #deque的用法总结 In [1]: """ 所在地址:from collections import deque 现在知道的情况总结: 1.deque的用法与list ...

  2. luoguP3261_[JLOI2015]城池攻占

    题意 有一棵树\(n\)个节点,每个节点有一个防御值,以及两个属性,表示一个骑士占领该节点后攻击值是加还是乘,有\(m\)个骑士,有初始位置和初始攻击值,如果攻击值大于该节点的防御值,就能占领该节点, ...

  3. [WPF]BringIntoView

    1.在scrollview 中的frameworkelement可以使用 FE.BringIntoView(); 滚动到此控件. 2.该 方法能一个重载 Bottom.BringIntoView(ne ...

  4. HTML-简单动画

    简单动画 (1)简单动画通常称之为“过渡transition” Transition-property:需要过渡的属性,但是并非所有的属性都支持过渡. Transition-duration:过渡的时 ...

  5. 初探CSS - 5 创建

    CSS 创建 当读到一个样式表时,浏览器会根据它来格式化 HTML 文档. 如何插入样式表 插入样式表的方法有三种: 外部样式表(External style sheet) 内部样式表(Interna ...

  6. 76. Minimum Window Substring (JAVA)

    Given a string S and a string T, find the minimum window in S which will contain all the characters ...

  7. 微信获取token -1000

    最终翻看微信开发api找到需要去配置IP白名单.只需要配置访问来源IP即可.

  8. 百度贴吧自动回帖的两种方式,使用requests(urllib2)和selenium两种方式回帖

    本文介绍,回复贴吧指定某楼层主的帖子的方法.在这里不介绍无限发主贴和无限回复主贴的方法,无限发主题帖会爆吧,引起别人的反感,并且很容易遭到吧主的封杀:无限回主题帖,会让整个帖子的每楼的回复充满了自己的 ...

  9. Ubuntu16.04下caffe CPU版的详细安装步骤

    一.caffe简介 Caffe,是一个兼具表达性.速度和思维模块化的深度学习框架. 由伯克利人工智能研究小组和伯克利视觉和学习中心开发. 虽然其内核是用C++编写的,但Caffe有Python和Mat ...

  10. List&LinQ

    DataTable会将整个数据表接收过来,可真正使用的数据未必是整个数据表所有的数据. 使用List可以接收需要使用的数据 public class Data_Model { public strin ...