当我进入搜索时,结果不会显示

时间:2015-07-24 09:03:21

标签: java sql servlets arraylist

LabServiceManagement.Java

    package com.bean;

    public class LabServiceManagement {
    private String lspName;
    private String address;
    private int zipcode;
    private String state;
    private String city;
    private String testName;
    private int testCode;
    private String testDescription;
    private double costOfTest;
    private String lab_home;
    public String getLspName() {
        return lspName;
    }
    public void setLspName(String lspName) {
        this.lspName = lspName;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public int getZipcode() {
        return zipcode;
    }
    public void setZipcode(int zipcode) {
        this.zipcode = zipcode;
    }
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getTestName() {
        return testName;
    }
    public void setTestName(String testName) {
        this.testName = testName;
    }
    public int getTestCode() {
        return testCode;
    }
    public void setTestCode(int testCode) {
        this.testCode = testCode;
    }
    public String getTestDescription() {
        return testDescription;
    }
    public void setTestDescription(String testDescription) {
        this.testDescription = testDescription;
    }
    public double getCostOfTest() {
        return costOfTest;
    }
    public void setCostOfTest(double costOfTest) {
        this.costOfTest = costOfTest;
    }
    public String getLab_home() {
        return lab_home;


    }
    public void setLab_home(String lab_home) {
        this.lab_home = lab_home;
    }



    }

DBUtility.java

package com.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


public class DBUtility {

static final String driver = "oracle.jdbc.driver.OracleDriver";
static final String dbURL = "jdbc:oracle:thin:@172.26.132.40:1521:ORCLILP";
static final String dbUserName = "aja16core";
static final String dbPassword = "aja16core";

public static Connection getConnection()
{
    Connection con=null;
    try {
        // load the JDBC-ODBC Bridge driver
        Class.forName(driver);
        // connect to db using DriverManager
        con = DriverManager.getConnection(dbURL, dbUserName, dbPassword);
        } 
        catch (ClassNotFoundException | SQLException e)
            {
            e.printStackTrace();
            }

    return con;
}
public static void closeResultSet(ResultSet rs) {
    if(rs!= null)
    {
        try
        {
            rs.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
    }

}

public static void closeStatement(PreparedStatement ps) {
    if(ps!= null)
    {
        try
        {
            ps.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
    }


}

public static void closeConnection(Connection con) {
    if(con!= null)
    {
        try
        {
            con.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
    }


}


}

LabServiceDAO.java

package com.dao;
import com.bean.LabServiceManagement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class LabServiceDAO {
public ArrayList<LabServiceManagement> searchcity(String city)
{
    ArrayList<LabServiceManagement> result_list= new ArrayList<LabServiceManagement>();
    Connection con=DBUtility.getConnection();
    PreparedStatement ps=null;
    ResultSet rs=null;
    try
    {
        ps=con.prepareStatement("select * from LSP where CITY=? ");
        ps.setString(1, city);
        rs=ps.executeQuery();
        while(rs.next())
        {
        String lspName=rs.getString("lspName");
        String address=rs.getString("address");
        int zipcode=rs.getInt("zipcode");
        String state=rs.getString("state");
        String testName=rs.getString("testName");
        int testCode=rs.getInt("testCode");
        String testDescription =rs.getString("testDescription");
        double costOfTest=rs.getDouble("costOfTest");
        String lab_home=rs.getString("lab_home");
        LabServiceManagement l=new LabServiceManagement();
        l.setLspName(lspName);
        l.setAddress(address);
        l.setZipcode(zipcode);
        l.setState(state);
        l.setCity(city);
        l.setTestName(testName);
        l.setTestCode(testCode);
        l.setTestDescription(testDescription);
        l.setCostOfTest(costOfTest);
        l.setLab_home(lab_home);

        result_list.add(l);
        }
    } catch (SQLException e)
    {
        e.printStackTrace();
    }
    finally
    {
        DBUtility.closeResultSet(rs);
        DBUtility.closeStatement(ps);
        DBUtility.closeConnection(con);
    }
    return result_list;



    }
}

LabService.java

package com.service;
import java.util.ArrayList;
import com.bean.LabServiceManagement;
import com.dao.LabServiceDAO;

public class LabService {

public ArrayList<LabServiceManagement> searchcity(String city) 
{
    LabServiceDAO searchdao = new LabServiceDAO();
    ArrayList<LabServiceManagement> result_list= searchdao.searchcity(city);
    return result_list;
}

}
  1. 我在SQL中创建了表
  2. 我插入了一些数据
  3. 我只为搜索城市编码,在那里我给了mumbai,已经存在于数据库中,但结果集不会出现
  4. 你能找到错误,我错了吗?

0 个答案:

没有答案