for(int i=0;i <2;i++){
String loadFriendSql= "select YYID,呢称,年龄,性别,自我介绍,籍贯,IP,status from YYCustomerInformation where YYID=? ";
PreparedStatement load2= conn3.prepareStatement(loadFriendSql);
load2.clearParameters();
load2.setString(1,YYfriendNo[i].trim());
//YYfriendNo[0]可以正确查询,YYfriendNo[1]查询就出错了,(YYfriendNo[i]中的值存在并正确,但是运行查询时报错说SQLEXCEPTION,)
ResultSet r5=load2.executeQuery();
System.out.println( "执行r5 ");
while(r5.next()){
dos.writeUTF(r5.getString( "YYID "));
dos.writeUTF(r5.getString( "呢称 "));
dos.writeUTF(r5.getString( "年龄 "));
dos.writeUTF(r5.getString( "性别 "));
System.out.println(r5.getString( "性别 "));
dos.writeUTF(r5.getString( "自我介绍 "));
System.out.println(r5.getString( "自我介绍 "));
dos.writeUTF(r5.getString( "籍贯 "));
dos.writeUTF(r5.getString( "IP "));
dos.writeUTF(r5.getString( "status "));
dos.flush();//下载信息
}
r5.close();
}
r4.close();
------解决方案--------------------
prepareStatement不要放在for循环中。
------解决方案--------------------
恩,prepareStatement定义放在外边,或者在循环后,用完初始化。。。