时间:2021-07-01 10:21:17 帮助过:91人阅读
具体代码如下,传入的date是D2014,数据库中真实存在的应该是4个元素,格式应该是这样【数学.20:30-21:20】,但是,通过该代码得到的结果集,打印之后显示4个D2014。求大神能够指出问题所在。
public ArrayList queryLesson(String date){ ArrayList lessonInfos=new ArrayList(); Connection con = null; PreparedStatement pre = null; ResultSet rs=null; DBcon conns = new DBcon(); con = conns.getConnection(); try { pre=con.prepareStatement("SELECT ? FROM lessoninfo"); pre.setString(1, date); rs=pre.executeQuery(); while(rs.next()){ System.out.println(rs.getString(date)); LessonInfo lessonInfo=new LessonInfo(); String[] result = rs.getString(date).split("\\."); if(result.length == 2){ lessonInfo.setLessonName(result[0]); lessonInfo.setLessonTime(result[1]); } lessonInfos.add(lessonInfo); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { con.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return lessonInfos;}