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数据科学实战
18
|
第
1
章
DROP TABLE
<tablename>;
下面的命令删除整个数据库及其所有内容:
DROP DATABASE
<databasename>;
1.5.3
 
Java
数据库连接
Java
数据库连接(
JDBC
)是连接
Java
应用与任何支持
SQL
的数据库的协议。每个数据库
提供商都有独立的
JAR
文件作为
JDBC
驱动程序,在构建及运行时,必须引入该文件。不
论是哪个数据库提供商,
JDBC
技术都致力于在各种应用与数据库之间提供统一的接口。
1.
连接
使用
JDBC
连接到数据库是非常简单方便的。只需为数据库填写适当格式的
URI
(统一资
源标识符),通常的格式如下:
String uri = "jdbc:<dbtype>:[location]/<dbname>?<parameters>"
DriverManager.getConnection()
方法会抛出异常,处理该异常有两种选择。目前
Java
的做
法是把连接放在
try
语句中,这称为
在
try
语句中调用资源
(
try with resource
)。采用这种
方法,执行
try
程序段之后,连接会自动关闭,因此不必再显式调用
Connection.close()
方法。记住,如果决定把连接语句置入实际的
try
程序段中(而不是在
try
语句中),那么
需要自己显式地关闭连接(很可能是在
finally
程序段中)。
String uri = "jdbc:mysql://localhost:3306/myDB?user=root";
try
(Connection c = DriverManager.getConnection(uri)) ...
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