package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONObject;
import Json.JsonUtil;
import entity.InfoMesg;
import entity.Types;
public class InfoMesgDao {
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
//查询主类类表
public List getMainType()
{
List list=new ArrayList();
String sql="select * from types where topNum='0'";
try {
conn=BaseDao.getconn();
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next())
{
Types types=new Types();
types.setTid(rs.getInt("Tid"));
types.setTopNum(rs.getInt("topNum"));
types.setTypeN(rs.getString("typeN"));
types.setTypeNum(rs.getInt("typeNum"));
list.add(types);
}
} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
BaseDao.closeAll(conn, ps, rs);
}
return list;
}
/**
* 根据上级编号查询子类
*/
public JSONObject getChildType(int Tnum)
{
List list=new ArrayList();
String sql="";
if(Tnum!=0)
{
sql="select * from types where topNum="+Tnum;
}else{
sql="select * from types where topNum=1";
}
try {
conn=BaseDao.getconn();
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next())
{
Types types=new Types();
types.setTid(rs.getInt("Tid"));
types.setTopNum(rs.getInt("topNum"));
types.setTypeN(rs.getString("typeN"));
types.setTypeNum(rs.getInt("typeNum"));
list.add(types);
}
} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
BaseDao.closeAll(conn, ps, rs);
}
JSONObject json= JsonUtil.generate(list); //将list转换成json
return json;
}
/**
* 根据子类编号查询详细信息
*/
public List getInfoByChildNum(int childNum)
{
List list=new ArrayList();
String sql="select * from InfoMesg where Inum="+childNum;
try {
conn=BaseDao.getconn();
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next())
{
InfoMesg mes=new InfoMesg();
mes.setIid(rs.getInt("Iid"));
mes.setIclor(rs.getString("Iclor"));
mes.setIname(rs.getString("Iname"));
mes.setInum(rs.getInt("Inum"));
list.add(mes);
}
} catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
BaseDao.closeAll(conn, ps, rs);
}
//JSONObject json= JsonUtil.generate(list);
System.out.print(list);
return list;
}
}
- 1
- 2
前往页