Skip to Content
Java数据科学实战
book

Java数据科学实战

by Michael R. Brzustowicz, PhD
January 2020
Intermediate to advanced
202 pages
5h 41m
Chinese
Posts & Telecom Press
Content preview from Java数据科学实战
20
|
第
1
章
4.
结果集
SELECT
语句会返回结果。每次编写
SELECT
语句时,都需要调用
Statement.executeQuery()
方法,而不是
execute()
方法,并且要把返回结果赋值给
ResultSet
。在数据库术语
中,
ResultSet
是游标,它是可迭代的数据结构。
Java
类
ResultSet
本身实现了
Java
接口
Iterator
,从而可以使用熟悉的
while-next
循环。
String selectSQL = "SELECT id, yr, city FROM data";
Statement st = c.createStatement();
ResultSet rs = st.executeQuery(selectSQL);
while
(rs.next()) {
int
id = rs.getInt("id");
int
year = rs.getInt("yr");
String city = rs.getString("city"));
// TODO,对每一行的值进行处理
}
rs.close();
st.close();
就像需要对文件逐行进行读取那样,你必须决定如何处理数据。你也许要把每个值存入与
值同类型的数组中,或者会把每行数据存入到一个类中,再用该类来建立列表。注意,我
们现在正按照数据库模式,根据列名获取列值,进而从
ResultSet
实例中提取值。可以通
过从
1
开始递增列索引来实现。
1.6
 通过绘图将数据可视化
在数据科学中,数据可视化是令人兴奋的重要组成部分。大量可用的有趣数据与交互式图 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

云安全实用指南

云安全实用指南

Chris Dotson
Kafka权威指南

Kafka权威指南

Neha Narkhede, Gwen Shapira, Todd Palino

Publisher Resources

ISBN: 9787115533302