黑马程序员技术交流社区
标题:
JDBC学习
[打印本页]
作者:
abc1233
时间:
2019-9-12 08:51
标题:
JDBC学习
package
cn.itcast.jdbc
;
import
JDBCUtils.JDBCUtils
;
import
java.sql.
*
;
public class
JDBCUtilsDemo
{
public static void
main
(
String
[]
args
)
{
Connection
conn
=
null
;
Statement
state
=
null
;
ResultSet
rs
=
null
;
try
{
conn
=
JDBCUtils
.
getConncetion
()
;
state
=
conn
.
createStatement
()
;
rs
=
state
.
executeQuery
(
"select
*
from emp"
)
;
while
(
rs
.
next
())
{
int
id
=
rs
.
getInt
(
"id"
)
;
String
ename
=
rs
.
getString
(
"ename"
)
;
int
jobId
=
rs
.
getInt
(
"job_id"
)
;
int
mgr
=
rs
.
getInt
(
"mgr"
)
;
Date
joinDate
=
rs
.
getDate
(
"joindate"
)
;
double
salary
=
rs
.
getDouble
(
"salary"
)
;
double
bonus
=
rs
.
getDouble
(
"bonus"
)
;
System
.
out
.
println
(
id
+
"
\t
"
+
ename
+
"
\t
"
+
jobId
+
"
\t
"
+
mgr
+
"
\t
"
+
joinDate
+
"
\t
"
+
salary
+
"
\t
"
+
bonus
)
;
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
()
;
}
finally
{
JDBCUtils
.
close
(
rs
,
state
,
conn
)
;
}
}
}
day04-常用API&异常.pdf
2019-9-12 08:49 上传
点击文件名下载附件
456.25 KB, 下载次数: 21
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2