Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_java
提交
9fb8193e
S
skill_tree_java
项目概览
CSDN 技术社区
/
skill_tree_java
通知
43
Star
8
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_java
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
9fb8193e
编写于
11月 10, 2021
作者:
CSDN-Ada助手
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add questions
上级
d7c3af42
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
483 addition
and
2 deletion
+483
-2
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/Abstract.md
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/Abstract.md
+1
-1
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/DriverType.json
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/DriverType.json
+8
-0
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/DriverType.md
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/DriverType.md
+31
-0
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/CRUD.json
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/CRUD.json
+8
-0
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/CRUD.md
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/CRUD.md
+122
-0
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/PSQLConnection.json
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/PSQLConnection.json
+8
-0
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/PSQLConnection.md
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/PSQLConnection.md
+147
-0
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/Transaction.json
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/Transaction.json
+8
-0
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/Transaction.md
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/Transaction.md
+148
-0
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/config.json
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/config.json
+2
-1
未找到文件。
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/Abstract.md
浏览文件 @
9fb8193e
...
...
@@ -7,7 +7,7 @@
## 答案
```
JDBC只可以用来建立数据库的连接
```
## 选项
...
...
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/DriverType.json
0 → 100644
浏览文件 @
9fb8193e
{
"type"
:
"code_options"
,
"author"
:
"clong"
,
"source"
:
"DriverType.md"
,
"exercise_id"
:
""
,
"notebook_enable"
:
true
}
\ No newline at end of file
data/2.Java中阶/4.使用JDBC操作数据库/1.JDBC概述/DriverType.md
0 → 100644
浏览文件 @
9fb8193e
# JDBC Driver Type
以下不属于JDBC驱动类型的是:
## 答案
```
JDBC-TCP
```
## 选项
### A
```
JDBC-ODBC桥驱动
```
### B
```
JDBC-Native API
```
### C
```
JDBC-Net
```
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/CRUD.json
0 → 100644
浏览文件 @
9fb8193e
{
"type"
:
"code_options"
,
"author"
:
"clong"
,
"source"
:
"CRUD.md"
,
"exercise_id"
:
""
,
"notebook_enable"
:
true
}
\ No newline at end of file
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/CRUD.md
0 → 100644
浏览文件 @
9fb8193e
# JDBC CRUD
以下对数据库的操作错误的是:
## 答案
```
java
import
java.sql.*
;
public
class
CRUD
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://192.168.126.76:5432/ask_classifier"
,
"csdn"
,
"csdn"
);
Statement
stmt
=
conn
.
createStatement
();
String
sql
=
"drop FROM student where id = 1"
;
stmt
.
executeQuery
(
sql
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
## 选项
### A
```
java
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
CRUD
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://192.168.126.76:5432/ask_classifier"
,
"csdn"
,
"csdn"
);
Statement
stmt
=
conn
.
createStatement
();
String
sql
=
"INSERT INTO student "
+
"VALUES (1, '小明', '男', 18)"
;
stmt
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
### B
```
java
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
CRUD
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://192.168.126.76:5432/ask_classifier"
,
"csdn"
,
"csdn"
);
Statement
stmt
=
conn
.
createStatement
();
String
sql
=
"UPDATE student "
+
"SET age = 15 WHERE id = 1"
;
stmt
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
### C
```
java
import
java.sql.*
;
public
class
CRUD
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://192.168.126.76:5432/ask_classifier"
,
"csdn"
,
"csdn"
);
Statement
stmt
=
conn
.
createStatement
();
String
sql
=
"SELECT id, name, sex, age FROM student where id = 1"
;
ResultSet
rs
=
stmt
.
executeQuery
(
sql
);
while
(
rs
.
next
()){
int
id
=
rs
.
getInt
(
"id"
);
int
age
=
rs
.
getInt
(
"age"
);
String
name
=
rs
.
getString
(
"name"
);
String
sex
=
rs
.
getString
(
"sex"
);
System
.
out
.
println
(
"id:"
+
id
+
",name:"
+
name
+
",sex"
+
sex
+
",age:"
+
age
);
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/PSQLConnection.json
0 → 100644
浏览文件 @
9fb8193e
{
"type"
:
"code_options"
,
"author"
:
"clong"
,
"source"
:
"PSQLConnection.md"
,
"exercise_id"
:
""
,
"notebook_enable"
:
true
}
\ No newline at end of file
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/PSQLConnection.md
0 → 100644
浏览文件 @
9fb8193e
# PSQL Connection
以下连接postgre数据正确的是:
## 答案
```
java
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
PSQLConnection
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5432/test"
,
"root"
,
"root"
);
Statement
stmt
=
conn
.
createStatement
();
String
sql
=
"CREATE TABLE student "
+
"(id INTEGER not NULL, "
+
" name VARCHAR(255), "
+
" sex VARCHAR(255), "
+
" age INTEGER, "
+
" PRIMARY KEY ( id ))"
;
stmt
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
## 选项
### A
```
java
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
PSQLConnection
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost:5432/test"
);
Statement
stmt
=
conn
.
createStatement
();
String
sql
=
"CREATE TABLE student "
+
"(id INTEGER not NULL, "
+
" name VARCHAR(255), "
+
" sex VARCHAR(255), "
+
" age INTEGER, "
+
" PRIMARY KEY ( id ))"
;
stmt
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
### B
```
java
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
PSQLConnection
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://root:root@localhost:5432/test"
);
Statement
stmt
=
conn
.
createStatement
();
String
sql
=
"CREATE TABLE student "
+
"(id INTEGER not NULL, "
+
" name VARCHAR(255), "
+
" sex VARCHAR(255), "
+
" age INTEGER, "
+
" PRIMARY KEY ( id ))"
;
stmt
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
### C
```
java
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
public
class
PSQLConnection
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://localhost/test"
,
"root"
,
"root"
);
Statement
stmt
=
conn
.
createStatement
();
String
sql
=
"CREATE TABLE student "
+
"(id INTEGER not NULL, "
+
" name VARCHAR(255), "
+
" sex VARCHAR(255), "
+
" age INTEGER, "
+
" PRIMARY KEY ( id ))"
;
stmt
.
executeUpdate
(
sql
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/Transaction.json
0 → 100644
浏览文件 @
9fb8193e
{
"type"
:
"code_options"
,
"author"
:
"clong"
,
"source"
:
"Transaction.md"
,
"exercise_id"
:
""
,
"notebook_enable"
:
true
}
\ No newline at end of file
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/Transaction.md
0 → 100644
浏览文件 @
9fb8193e
# Transaction
以下关于事务的写法能达到出错回退的目的的是:
## 答案
```
java
import
java.sql.*
;
public
class
Transaction
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://192.168.126.76:5432/ask_classifier"
,
"csdn"
,
"csdn"
);
Statement
stmt
=
conn
.
createStatement
();
try
{
conn
.
setAutoCommit
(
false
);
String
insertSQL
=
"INSERT INTO student "
+
"VALUES (1, '小明', '男', 18)"
;
stmt
.
executeUpdate
(
insertSQL
);
String
updateSQL
=
"UPDATE student "
+
"SET age = 15 WHERE id = 1"
;
stmt
.
executeUpdate
(
updateSQL
);
String
deleteSQL
=
"delete FROM student where id = 1"
;
stmt
.
executeUpdate
(
deleteSQL
);
conn
.
commit
();
}
catch
(
SQLException
e
)
{
conn
.
rollback
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
## 选项
### A
```
java
import
java.sql.*
;
public
class
Transaction
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://192.168.126.76:5432/ask_classifier"
,
"csdn"
,
"csdn"
);
Statement
stmt
=
conn
.
createStatement
();
try
{
String
insertSQL
=
"INSERT INTO student "
+
"VALUES (1, '小明', '男', 18)"
;
stmt
.
executeUpdate
(
insertSQL
);
String
updateSQL
=
"UPDATE student "
+
"SET age = 15 WHERE id = 1"
;
stmt
.
executeUpdate
(
updateSQL
);
String
deleteSQL
=
"delete FROM student where id = 1"
;
stmt
.
executeUpdate
(
deleteSQL
);
conn
.
commit
();
}
catch
(
SQLException
e
)
{
conn
.
rollback
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
### B
```
java
import
java.sql.*
;
public
class
Transaction
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://192.168.126.76:5432/ask_classifier"
,
"csdn"
,
"csdn"
);
Statement
stmt
=
conn
.
createStatement
();
try
{
String
insertSQL
=
"INSERT INTO student "
+
"VALUES (1, '小明', '男', 18)"
;
stmt
.
executeUpdate
(
insertSQL
);
String
updateSQL
=
"UPDATE student "
+
"SET age = 15 WHERE id = 1"
;
stmt
.
executeUpdate
(
updateSQL
);
String
deleteSQL
=
"delete FROM student where id = 1"
;
stmt
.
executeUpdate
(
deleteSQL
);
}
catch
(
SQLException
e
)
{
conn
.
rollback
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
### C
```
java
import
java.sql.*
;
public
class
Transaction
{
public
static
void
main
(
String
[]
args
)
throws
ClassNotFoundException
,
SQLException
{
Connection
conn
=
null
;
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
conn
=
DriverManager
.
getConnection
(
"jdbc:postgresql://192.168.126.76:5432/ask_classifier"
,
"csdn"
,
"csdn"
);
Statement
stmt
=
conn
.
createStatement
();
conn
.
setAutoCommit
(
false
);
String
insertSQL
=
"INSERT INTO student "
+
"VALUES (1, '小明', '男', 18)"
;
stmt
.
executeUpdate
(
insertSQL
);
String
updateSQL
=
"UPDATE student "
+
"SET age = 15 WHERE id = 1"
;
stmt
.
executeUpdate
(
updateSQL
);
String
deleteSQL
=
"delete FROM student where id = 1"
;
stmt
.
executeUpdate
(
deleteSQL
);
conn
.
commit
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
conn
!=
null
)
{
conn
.
close
();
}
}
}
}
```
data/2.Java中阶/4.使用JDBC操作数据库/2.数据库操作/config.json
浏览文件 @
9fb8193e
...
...
@@ -98,6 +98,6 @@
}
}
],
"export"
:
[],
"export"
:
[
"PSQLConnection.json"
,
"CRUD.json"
,
"Transaction.json"
],
"title"
:
"数据库操作"
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录