- Java code
public BasicInf getBasicInf(String staId){ BasicInf BasicInf=null; try{ ps = connection.prepareStatement("select * from BasicInf where staId=?"); ps.setString(1,staId); ResultSet rs = ps.executeQuery(); while (rs.next()) { System.out.println(rs.getString(1)); System.out.println(rs.getString(2)); System.out.println(rs.getString(3)); System.out.println(rs.getString(4)); BasicInf.setStaId(rs.getString(1)); BasicInf.setBirthday(rs.getString(2)); BasicInf.setNation(rs.getString(4)); BasicInf.setSex(rs.getString(3)); return BasicInf; } }catch(Exception e) { e.printStackTrace(); } return BasicInf; }
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));正确输出了数据库里的数据
可是到了BasicInf.setStaId(rs.getString(1));就直接catch了,也不知道错在哪里,求大神们帮帮忙看下,分不多笑纳
------解决方案--------------------
你又把BasicInf设置成null了