Home  >  Article  >  Database  >  servlet连接mysql数据库,通过查询语句得到的结果集,打印之后发现不正确。

servlet连接mysql数据库,通过查询语句得到的结果集,打印之后发现不正确。

WBOY
WBOYOriginal
2016-06-06 09:44:171440browse

mysqlservletjavaresultset

具体代码如下,传入的date是D2014,数据库中真实存在的应该是4个元素,格式应该是这样【数学.20:30-21:20】,但是,通过该代码得到的结果集,打印之后显示4个D2014。求大神能够指出问题所在。

<code>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;}</lessoninfo></lessoninfo></lessoninfo></code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn