我已经把代码改成这样了还是返回一个0啊
public int kouanID(String kouan)
{
int kouanid=0;
try
{
PreparedStatement ps = DB.getPs("select kouanid from kouanbiao where kouanmingcheng = '"+kouan+"'"); ResultSet rs = ps.executeQuery();
while(rs.next())
{
kouanid = rs.getInt("kouanid");
}
}catch(Exception e)
{
e.printStackTrace();
}
return kouanid;
} kouan = request.getParameter("kouan");
kouanid = this.kouanID(kouan);
pw.print(kouanid);
public int kouanID(String kouan)
{
int kouanid=0;
try
{
PreparedStatement ps = DB.getPs("select kouanid from kouanbiao where kouanmingcheng = '"+kouan+"'"); ResultSet rs = ps.executeQuery();
while(rs.next())
{
kouanid = rs.getInt("kouanid");
}
}catch(Exception e)
{
e.printStackTrace();
}
return kouanid;
} kouan = request.getParameter("kouan");
kouanid = this.kouanID(kouan);
pw.print(kouanid);
1. 首先在数据库中运行sql 语句 select kouanid from kouanbiao where kouanmingcheng = 'kouan' 看看能不能得到结果,如果不能得到结果,则插入一条测试数据;2.如果运行1能得到结果,从你的程序中,基本可以确定是 DB.getPs() 出错了,你最好把这段程序也贴出来。导致 DB.getPs()出错的可能性有这么几种
1) 没有正确的加载驱动程序
2) 连接数据库的参数写错3. 这些都正确的话,那看看kouanid 这个列在数据库中是否为 整型数据类型?
kouanbiao中kouanmingcheng为"kouan"的数据"kouanid"字段的值为0
有什么好BS做广告的,至少我尽力给lz回答问题了,而且我的广告也没到处做,从我的角度看,我只是去尽力帮助别人之后,用自己的劳动换一个贴广告的地方也不可以?