62,615
社区成员
发帖
与我相关
我的任务
分享
public List<To_DingDan> findByHyId3(Integer id) throws Exception{
String sql = "select * from (select * from to_dingdan t where t.hyid="+id+" and t.type='待付款' order by t.id desc) j group by j.hyid2 order by j.id desc";
// 获取到连接
List<To_DingDan> list = new ArrayList<To_DingDan>();
// 获取到连接
//加载驱动
Class.forName("com.mysql.jdbc.Driver");
//获取连接Connection
Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/jiaju4?useUnicode=true&characterEncoding=UTF8", "root", "123456");
//得到执行sql语句的对象Statement
Statement stmt = (Statement) conn.createStatement();
//执行sql语句,并返回结果
ResultSet rs = (ResultSet) stmt.executeQuery(sql);
//(rs.next() 本地测试true 部署到服务器false;
while (rs.next()) {
// 将查询出的内容添加到list中,其中userName为数据库中的字段名称
System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
To_DingDan dd = new To_DingDan();
dd.setHyid2(rs.getInt("hyid2"));
list.add(dd);
}
rs.close();
stmt.close();
conn.close();
System.out.println(list.size()+"******************");
return list;
}