黑马程序员技术交流社区
标题:
【成都校区】随堂作业未副自定义的job类
[打印本页]
作者:
梅德韦杰夫
时间:
2018-12-5 20:39
标题:
【成都校区】随堂作业未副自定义的job类
package cn.jdbc.Day5;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class map {
public static void main(String[] args) {
List<Job> a=fineAll();
for (Job job : a) {
System.out.println(job);
}
}
public static List<Job> fineAll(){
Connection conn=null;
Statement stat=null;
ResultSet rls=null;
List<Job> list=new ArrayList<>();
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/uul", "root", "root");
stat = conn.createStatement();
rls = stat.executeQuery("select * from job");
while(rls.next()){
Job job = new Job();
int id=rls.getInt("id");
String jname=rls.getString("jname");
String description=rls.getString("description");
job.setId(id);
job.setJname(jname);
job.setDescription(description);
list.add(job);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally {
if (rls!=null){
try {
rls.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (stat!=null){
try {
stat.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (conn!=null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return list;
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2