運(yùn)行index.jsp出現(xiàn)這樣的報(bào)錯(cuò)java.sql.SQLException: No value specified for parameter 1
運(yùn)行index.jsp出現(xiàn)這樣的報(bào)錯(cuò)java.sql.SQLException: No value specified for parameter 1
然后只出現(xiàn)商品展示四個(gè)字 什么內(nèi)容也木有了?
我的代碼是
<h1>
<B>商品展示<B>
</h1>
<hr>
<center>
<table width="750" height="60" cellpadding="0" cellspacing="0"
border="0">
<tr>
<td>
<!-- 商品循環(huán)開(kāi)始 -->
<%
? ? ? ? ?ItemsDAO itemsDao = new ItemsDAO();
? ? ? ? ?ArrayList<Items> list = itemsDao.getAllItems();
? ? ? ? ?if (list != null && list.size() > 0) {
? ? ? ? for (int i = 0; i < list.size(); i++) {
? ? ? ? ? ?Items item = list.get(i);
? ? ? ? ?%>?
?
<div>
<dl>
<dt>
<a href="details.jsp?id=<%=item.getId()%>"><img
src="images/<%=item.getPicture()%>" width="120" height="90"
border="1" /></a>
</dt>
<dd class="dd_name"><%=item.getName()%></dd>
<dd class="dd_press">出版社:<%=item.getPress()%></dd>
<dd class="dd_price">價(jià)格:¥<%=item.getPrice()%></dd>
</dl>
</div> <!-- 商品循環(huán)結(jié)束 -->
<%
}
? } ? ? ? ? ? ? ??
? %>
求教求教
2015-12-10
sql語(yǔ)句掛掉了。把你的Statement對(duì)象toString打印一下,在控制臺(tái)里看看sql語(yǔ)句,看哪錯(cuò)了。
2015-12-10
public class ItemsDAO {
//獲得所有的商品信息
public ArrayList<Items> getAllItems(){
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
ArrayList<Items>list = new ArrayList<Items>();//商品集合
try{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/items","root","123456");
String sql = "select * from items where id =?;";//SOL語(yǔ)句
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while(rs.next()){//商品初始化
Items item = new Items();
item.setId(rs.getInt("id"));
item.setName(rs.getString("name"));
item.setPress(rs.getString("press"));
item.setNumber(rs.getInt("number"));
item.setPrice(rs.getInt("price"));
item.setPicture(rs.getString("picture"));
item.setNumber(rs.getInt("number"));
list.add(item);//把一個(gè)商品加入集合
}
return list;//返回集合
}
catch(Exception ex){
ex.printStackTrace();
return null;
}finally{
//釋放數(shù)據(jù)集對(duì)象
if(rs != null){
try{
rs.close();
rs = null;
}
catch(Exception ex){
ex.printStackTrace();
}
//釋放語(yǔ)句對(duì)象
if(stmt != null){
try{
stmt.close();
stmt = null;
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
}
}
我的DAO類是這樣的 但是我不知道哪里不對(duì)呢 求指教
2015-12-10
你的preparestatement沒(méi)有傳參數(shù)1的值,已經(jīng)報(bào)出來(lái)了
看一下你后臺(tái)DAO類寫的語(yǔ)句對(duì)不對(duì)