主题:如何从数据库中读取数据并返回页面上
我也了一个,总是不成功,各位指点一下.
try{DBAccess newAccess = new DBAccess("127.0.0.1:1433","wu","sa","sa");
String sql = null;
ArrayList resultList = new ArrayList();
//sql = "insert into time_zone(Use_leap_seconds) values('N')";
//resultList.add(sql);
//sql = "update time_zone set Use_leap_seconds='Y' where Use_leap_seconds='N'";
//resultList.add(sql);
//newAccess.executeUpdate(resultList);
sql = "select Course,Student,BookName from Book WHERE TeacherID='11111'"; //添加接口
resultList = newAccess.executeQuery(sql);
for(int i=0;i<resultList.size();i++){
HashMap hash=(HashMap)resultList.get(i);
String course=hash.get("Course").toString();
String student=hash.get("Student").toString();
String bookname=hash.get("BookName").toString();
out.println("课程名称是"+course+",学生专业是"+student);
//if(bookname==null)
// out.println("你尚未提交教材,请提交");
//else
//out.println("你已经选择了教材,教材名称是"+bookname);
}
newAccess.close();}catch(DBException e){
out.println("the exception is----"+e);
}
try{DBAccess newAccess = new DBAccess("127.0.0.1:1433","wu","sa","sa");
String sql = null;
ArrayList resultList = new ArrayList();
//sql = "insert into time_zone(Use_leap_seconds) values('N')";
//resultList.add(sql);
//sql = "update time_zone set Use_leap_seconds='Y' where Use_leap_seconds='N'";
//resultList.add(sql);
//newAccess.executeUpdate(resultList);
sql = "select Course,Student,BookName from Book WHERE TeacherID='11111'"; //添加接口
resultList = newAccess.executeQuery(sql);
for(int i=0;i<resultList.size();i++){
HashMap hash=(HashMap)resultList.get(i);
String course=hash.get("Course").toString();
String student=hash.get("Student").toString();
String bookname=hash.get("BookName").toString();
out.println("课程名称是"+course+",学生专业是"+student);
//if(bookname==null)
// out.println("你尚未提交教材,请提交");
//else
//out.println("你已经选择了教材,教材名称是"+bookname);
}
newAccess.close();}catch(DBException e){
out.println("the exception is----"+e);
}