/** Created on 2007-7-16
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates*/packagedb;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.sql.Timestamp;importjava.text.SimpleDateFormat;importjava.util.ArrayList;importjava.util.List;/***@authorAdministrator
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates*/publicclassOpinionDAO
{publicintaddOpinion(Opinion opinion)
{
Connection con=null;
Statement st=null;//创建Statement对象ResultSet rs=null;try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/ActiveBPEL","sa","peace");
st=con.createStatement();
String name=opinion.getName();
String department=opinion.getDepartment();
String receiveTime=opinion.getReceiveTime();
String dealTime=opinion.getDealTime();
String content=opinion.getContent();intcarInfoId=opinion.getCarInfoId();intactivityId=opinion.getActivityId();
st
.executeUpdate("insert opinion(name,department,receiveTime,dealTime,content,carInfoId,activityId) values("+"'"+name+"','"+department+"','"+receiveTime+"','"+dealTime+"','"+content+"',"+carInfoId+","+activityId+")");
rs=st.executeQuery("select max(opinionId) from opinion");intopinionId=-1;while(rs.next())
{
opinionId=rs.getInt(1);
}returnopinionId;
}catch(Exception e)
{//TODO Auto-generated catch blocke.printStackTrace();
}finally{if(rs!=null)
{try{
rs.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
rs=null;
}if(st!=null)
{try{
st.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
st=null;
}if(con!=null)
{try{
con.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
con=null;
}
}return-1;
}publicvoidupdateOpinion(Opinion opinion)
{
Connection con=null;
Statement st=null;//创建Statement对象try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/ActiveBPEL","sa","peace");
st=con.createStatement();intopinionId=opinion.getOpinionId();
String name=opinion.getName();
String department=opinion.getDepartment();
String receiveTime=opinion.getReceiveTime();
String dealTime=opinion.getDealTime();
String content=opinion.getContent();intcarInfoId=opinion.getCarInfoId();intactivityId=opinion.getActivityId();
st
.executeUpdate("update opinion set name="+"'"+name+"',department='"+department+"',receiveTime='"+receiveTime+"',dealTime='"+dealTime+"',content='"+content+"',carInfoId="+carInfoId+",activityId="+activityId+"where opinionId="+opinionId);//输出被查询的情况}catch(Exception e)
{//TODO Auto-generated catch blocke.printStackTrace();
}finally{if(st!=null)
{try{
st.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
st=null;
}if(con!=null)
{try{
con.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
con=null;
}
}
}publicList getOpinions(intcarInfoId)
{
Connection con=null;
Statement st=null;//创建Statement对象ResultSet rs=null;
List opinions=newArrayList();try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/ActiveBPEL","sa","peace");
st=con.createStatement();
rs=st.executeQuery("select * from opinion where carInfoId="+carInfoId);while(rs.next())
{
Opinion opinion=newOpinion();
opinion.setOpinionId(rs.getInt("opinionId"));
opinion.setName(rs.getString("name"));
opinion.setDepartment(rs.getString("department"));
Timestamp timee=rs.getTimestamp("receiveTime");
SimpleDateFormat myFormat=newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String mystrdate="";if(timee!=null)
{
mystrdate=myFormat.format(timee);
}
opinion.setReceiveTime(mystrdate);
timee=rs.getTimestamp("dealTime");if(timee!=null)
{
mystrdate=myFormat.format(timee);
}
opinion.setDealTime(mystrdate);
opinion.setContent(rs.getString("content"));
opinion.setCarInfoId(rs.getInt("carInfoId"));
opinion.setActivityId(rs.getInt("activityId"));
opinions.add(opinion);
}returnopinions;//输出被查询的情况}catch(Exception e)
{//TODO Auto-generated catch blocke.printStackTrace();
}finally{if(rs!=null)
{try{
rs.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
rs=null;
}if(st!=null)
{try{
st.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
st=null;
}if(con!=null)
{try{
con.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
con=null;
}
}returnnull;
}publicOpinion getOpinion(intcarInfoId,intactivityId)
{
Connection con=null;
Statement st=null;//创建Statement对象ResultSet rs=null;
Opinion opinion=newOpinion();try{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
con=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/ActiveBPEL","sa","peace");
st=con.createStatement();
rs=st.executeQuery("select opinionId,content from opinion where carInfoId="+carInfoId+"and activityId="+activityId);while(rs.next())
{
opinion.setOpinionId(rs.getInt("opinionId"));
opinion.setContent(rs.getString("content"));
}returnopinion;//输出被查询的情况}catch(Exception e)
{//TODO Auto-generated catch blocke.printStackTrace();
}finally{if(rs!=null)
{try{
rs.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
rs=null;
}if(st!=null)
{try{
st.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
st=null;
}if(con!=null)
{try{
con.close();
}catch(SQLException e1)
{//TODO Auto-generated catch blocke1.printStackTrace();
}
con=null;
}
}returnopinion;
}
}