界面無(wú)法讀取數(shù)據(jù)庫(kù)并顯示,數(shù)據(jù)庫(kù)配置沒(méi)問(wèn)題,測(cè)試過(guò),可以正常查詢
package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import util.DBUtils;
import entity.Items;
public class DBItems {
public ArrayList<Items> getAllItems(){
Connection conn = null ;
PreparedStatement pst = null ;
ResultSet rs = null ;
ArrayList<Items> itemList = new ArrayList<Items>();
try {
conn=DBUtils.getConnection();
String sql = "select * from items";
pst = conn.prepareStatement(sql);
rs=pst.executeQuery();
while(rs.next()){
Items item = new Items();
item.setId(rs.getInt("id"));
item.setName(rs.getString("name"));
item.setCity(rs.getString("city"));
item.setNumber(rs.getInt("number"));
item.setPrice(rs.getInt("price"));
item.setPicture(rs.getString("picture"));
itemList.add(item);
}
return itemList;
} catch(Exception ex)
{
ex.printStackTrace();
return null;
}
/*
* 釋放資源
* */
finally{
if (pst!=null) {
try {
pst.close();
pst=null;
}catch(Exception ex)
{
ex.printStackTrace();
}
}
if (rs!=null) {
try {
rs.close();
rs=null;
} catch(Exception ex)
{
ex.printStackTrace();
}
}
}
}
}
只要連接數(shù)據(jù)庫(kù)就一直提示,錯(cuò)誤,在14行,14行修改15又錯(cuò)誤,15行修改,16行又錯(cuò)。。然后循環(huán),不連接數(shù)據(jù)庫(kù)光顯示靜態(tài)網(wǎng)頁(yè)就沒(méi)錯(cuò)誤,
數(shù)據(jù)庫(kù)配置沒(méi)問(wèn)題,測(cè)試過(guò),可以正常查詢,但是只要index.jsp中讀取并使用數(shù)據(jù)庫(kù)中內(nèi)容,就會(huì)出錯(cuò)。。。是在找不到原因了,
希望大神解答,謝謝!??!
2016-06-13
問(wèn)題解決了,粗心大意啊。。。
連接數(shù)據(jù)庫(kù)時(shí),數(shù)據(jù)庫(kù)的jar包一定要放在WEB-INF文件夾中,如果還出錯(cuò),就把jar包放在Tomcat安裝目錄的lib文件夾下面