
用jsp连接数据库出现了对于PreparedStatement 或 CallableStatement,方法 executeQuery()不能带有参数。
这是出现queryBySql的地方Stringsql="select*fromauthors";returnqueryBySql(sql,newAuthorRowMapp...
这是出现queryBySql的地方
String sql = "select * from authors "; return queryBySql(sql, new AuthorRowMapper());
List<AuthorModel> models = queryBySql(sql, new AuthorRowMapper());
public List queryBySql(String sql,IRowMapper mapper){ Connection coon = null; Statement stmt = null; ResultSet rs = null; List retList = new ArrayList(); try { coon = dbCoon.getConnection(); stmt = coon.prepareStatement(sql); rs = stmt.executeQuery(sql); while (rs.next()){ Object obj =mapper.mappingRow(rs); //AuthorModel model = new AuthorModel(rs.getInt("authorid"), //rs.getString("firstName"),rs.getString("lastName")); retList.add(obj); } } catch (SQLException e) { e.printStackTrace(); }finally{ dbCoon.closeResultSet(rs); dbCoon.closeStatement(stmt); dbCoon.closeConnectiion(coon); } return retList; } public List queryBySql(String sql,IParamBinding bind,IRowMapper mapper){ Connection coon = null; PreparedStatement pstmt = null; ResultSet rs = null; List retList = new ArrayList(); try { coon = dbCoon.getConnection(); pstmt = coon.prepareStatement(sql); bind.bindParam(pstmt);//参数绑定 rs = pstmt.executeQuery(); while (rs.next()){ Object obj =mapper.mappingRow(rs); //AuthorModel model = new AuthorModel(rs.getInt("authorid"), //rs.getString("firstName"),rs.getString("lastName")); retList.add(obj); } } catch (SQLException e) { e.printStackTrace(); }finally{ dbCoon.closeResultSet(rs); dbCoon.closeStatement(pstmt); dbCoon.closeConnectiion(coon); } return retList; }} 展开
String sql = "select * from authors "; return queryBySql(sql, new AuthorRowMapper());
List<AuthorModel> models = queryBySql(sql, new AuthorRowMapper());
public List queryBySql(String sql,IRowMapper mapper){ Connection coon = null; Statement stmt = null; ResultSet rs = null; List retList = new ArrayList(); try { coon = dbCoon.getConnection(); stmt = coon.prepareStatement(sql); rs = stmt.executeQuery(sql); while (rs.next()){ Object obj =mapper.mappingRow(rs); //AuthorModel model = new AuthorModel(rs.getInt("authorid"), //rs.getString("firstName"),rs.getString("lastName")); retList.add(obj); } } catch (SQLException e) { e.printStackTrace(); }finally{ dbCoon.closeResultSet(rs); dbCoon.closeStatement(stmt); dbCoon.closeConnectiion(coon); } return retList; } public List queryBySql(String sql,IParamBinding bind,IRowMapper mapper){ Connection coon = null; PreparedStatement pstmt = null; ResultSet rs = null; List retList = new ArrayList(); try { coon = dbCoon.getConnection(); pstmt = coon.prepareStatement(sql); bind.bindParam(pstmt);//参数绑定 rs = pstmt.executeQuery(); while (rs.next()){ Object obj =mapper.mappingRow(rs); //AuthorModel model = new AuthorModel(rs.getInt("authorid"), //rs.getString("firstName"),rs.getString("lastName")); retList.add(obj); } } catch (SQLException e) { e.printStackTrace(); }finally{ dbCoon.closeResultSet(rs); dbCoon.closeStatement(pstmt); dbCoon.closeConnectiion(coon); } return retList; }} 展开
2014-01-01
展开全部
这段代码应该是好的。
那些mapper的类,是如何的
那些mapper的类,是如何的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |