链接数据库查询 while 循环时 为false 但是明明能查出来数据。代码如下
高洛峰
高洛峰 2016-11-10 09:52:19
0
1
572

我把sql语句在数据库里面查过了 能查出来数据

 ps = con.prepareStatement("SELECT * from  position where name='"+pos+"'");
                re = ps.executeQuery();
                System.out.println(re.next()); // 为false
                while (re.next()) {
                    position = new Position();
                    position.setId(re.getInt("id"));
                    position.setNumber(re.getString("number"));
                    position.setName(re.getString("name"));
                    position.setLongitude(re.getString("longitude"));
                    position.setLatitude(re.getString("latitude"));
                    position.setLdatetime(re.getString("ldatetime"));
                    positionl.add(position);
                    System.out.println(positionl.size());
                }

查询的条件是一个数组,是循环的,但是每循环一次只有一条符合条件  。但是走到while(){}就进不去 显示false。难道只有一条数据进不去吗?不可能吧, 以前没有遇到过这种情况。。

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

répondre à tous(1)
三叔

你调用了一下next方法,游标往下走了,只有一条的情况下,while肯定不走了。。你可以使用re.hasNext()判断是否有数据。


Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!