日期:2014-05-18  浏览次数:20706 次

关于在一个jsp中调用一个数据库中两张表的数据
SearchDdwhoneServlet.java
package com.chk.doubleball.setvlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.chk.doubleball.model.Bonus;
import com.chk.doubleball.model.DdwhOne;
import com.chk.doubleball.util.DBUtil;

public class SearchDdwhoneServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletExceptionIOException {
// 1、查询数据
List<DdwhOne> ddwhoneList = new ArrayList<>();
List<Bonus> bonusList = new ArrayList<>();

String sql1 = "select * from t_bonus where _id > (select count(*) from t_bonus) - 100;";
String sql = "select * from t_ddwh01 where _id > (select count(*) from t_ddwh01) - 100;";
Connection conn = DBUtil.getConn();
PreparedStatement pstmt = null;
PreparedStatement pstmt1 = null;
ResultSet rs = null;
ResultSet rs1 = null;

try {
pstmt = conn.prepareStatement(sql);
pstmt1 = conn.prepareStatement(sql1);
rs = pstmt.executeQuery();
rs1 = pstmt1.executeQuery();
while(rs1.next()){
Bonus b = new Bonus();
b.setIssue(rs.getInt("issue"));
b.setOrder_red_one(rs.getString("order_red_one"));
b.setOrder_red_two(rs.getString("order_red_two"));
b.setOrder_red_three(rs.getString("order_red_three"));
b.setOrder_red_four(rs.getString("order_red_four"));
b.setOrder_red_five(rs.getString("order_red_five"));
b.setOrder_red_six(rs.getString("order_red_six"));
b.setBlue(rs.getString("blue"));
bonusList.add(b);

}
while (rs.next()) {
DdwhOne d = new DdwhOne();
d.setW_one(rs.getString("w_one"));
d.setW_two(rs.getString("w_two"));
d.setW_three(rs.getString("w_three"));
d.setW_four(rs.getString("w_four"));
d.setW_five(rs.getString("w_five"));