第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

運(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é)束 -->

<%

}

? } ? ? ? ? ? ? ??

? %>

求教求教

正在回答

3 回答

sql語(yǔ)句掛掉了。把你的Statement對(duì)象toString打印一下,在控制臺(tái)里看看sql語(yǔ)句,看哪錯(cuò)了。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

shenke 提問(wèn)者

非常感謝!好的
2015-12-10 回復(fù) 有任何疑惑可以回復(fù)我~

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ì)呢 求指教

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

sxian_wang

問(wèn)題在這里: String sql = "select * from items where id =?;";//SOL語(yǔ)句 stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); 你定義完sql語(yǔ)句的時(shí)候,對(duì)占位符?沒(méi)有進(jìn)行填充,直接就execute了,所以報(bào)錯(cuò)了。在execute之前用stmt.setObjec(int,Object)或stmt.setString(int,Strint)填充下sql語(yǔ)句再execute。
2015-12-10 回復(fù) 有任何疑惑可以回復(fù)我~

你的preparestatement沒(méi)有傳參數(shù)1的值,已經(jīng)報(bào)出來(lái)了

看一下你后臺(tái)DAO類寫的語(yǔ)句對(duì)不對(duì)

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

運(yùn)行index.jsp出現(xiàn)這樣的報(bào)錯(cuò)java.sql.SQLException: No value specified for parameter 1

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)