Listlist=newArrayList();try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");}catch(ClassNotFoundExceptionex){ex.printStackTrace();}Conne...
List list = new ArrayList();
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
Connection conn = null;
try {
String url ="jdbc:sqlserver://127.0.0.1:1433;databasename=test";
String userName="sa";
String password="123";
conn = DriverManager.getConnection(url, userName, password);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from employee");
while (rs.next()){
Employee employee = new Employee();
employee.employeeName = rs.getString("name");
list.add(employee);
}
rs.close();
st.close();
} catch (SQLException ex) {
ex.printStackTrace();
} finally{
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
request.setAttribute("obj", list);
request.getRequestDispatcher("/list.jsp").forward(request, response);
}
这个是连接数据库部分。。其他部分要怎么做呢,本人初识JAVA ,望高人不吝赐教~
员工资料只需要 编号,姓名,备注3项就好了
这个是连接数据库的~具体就是要在JSP里创建Employee的行和列,然后就是用户的请求通过servlet发送给JSP,完成操作后再通过web页面响应给用户
展开