具体代码如下,传入的date是D2014,数据库中真实存在的应该是4个元素,格式应该是这样【数学.20:30-21:20】,但是,通过该代码得到的结果集,打印之后显示4个D2014。求大神能够指出问题所在。
public ArrayList<LessonInfo> queryLesson(String date){
ArrayList<LessonInfo> lessonInfos=new ArrayList<LessonInfo>();
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;
}
你数据库中对应存储的应该是varchar2类型的,而不应该Date类型