<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    對于SQLserver中datetime類型數據的添加和讀取

    /*
     * Created on 2007-7-16
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     
    */
    package db;

    /**
     * 
    @author Administrator
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     
    */
    public class Opinion
    {
        
    private int opinionId=-1;
        
    private String name;
        
    private String department;
        
    private String receiveTime;
        
    private String dealTime;
        
    private String content="";
        
    private int carInfoId;
        
    private int activityId=-1;
        
        
    /**
         * 
    @return Returns the activityId.
         
    */
        
    public int getActivityId()
        {
            
    return activityId;
        }
        
    /**
         * 
    @param activityId The activityId to set.
         
    */
        
    public void setActivityId(int activityId)
        {
            
    this.activityId = activityId;
        }
        
    /**
         * 
    @return Returns the carInfoId.
         
    */
        
    public int getCarInfoId()
        {
            
    return carInfoId;
        }
        
    /**
         * 
    @param carInfoId The carInfoId to set.
         
    */
        
    public void setCarInfoId(int carInfoId)
        {
            
    this.carInfoId = carInfoId;
        }
        
    /**
         * 
    @return Returns the content.
         
    */
        
    public String getContent()
        {
            
    return content;
        }
        
    /**
         * 
    @param content The content to set.
         
    */
        
    public void setContent(String content)
        {
            
    this.content = content;
        }
        
    /**
         * 
    @return Returns the dealTime.
         
    */
        
    public String getDealTime()
        {
            
    return dealTime;
        }
        
    /**
         * 
    @param dealTime The dealTime to set.
         
    */
        
    public void setDealTime(String dealTime)
        {
            
    this.dealTime = dealTime;
        }
        
    /**
         * 
    @return Returns the department.
         
    */
        
    public String getDepartment()
        {
            
    return department;
        }
        
    /**
         * 
    @param department The department to set.
         
    */
        
    public void setDepartment(String department)
        {
            
    this.department = department;
        }
        
    /**
         * 
    @return Returns the name.
         
    */
        
    public String getName()
        {
            
    return name;
        }
        
    /**
         * 
    @param name The name to set.
         
    */
        
    public void setName(String name)
        {
            
    this.name = name;
        }
        
    /**
         * 
    @return Returns the opinionId.
         
    */
        
    public int getOpinionId()
        {
            
    return opinionId;
        }
        
    /**
         * 
    @param opinionId The opinionId to set.
         
    */
        
    public void setOpinionId(int opinionId)
        {
            
    this.opinionId = opinionId;
        }
        
    /**
         * 
    @return Returns the receiveTime.
         
    */
        
    public String getReceiveTime()
        {
            
    return receiveTime;
        }
        
    /**
         * 
    @param receiveTime The receiveTime to set.
         
    */
        
    public void setReceiveTime(String receiveTime)
        {
            
    this.receiveTime = receiveTime;
        }
    }
    /*
     * Created on 2007-7-16
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     
    */
    package db;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.Timestamp;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.List;

    /**
     * 
    @author Administrator
     * 
     * TODO To change the template for this generated type comment go to Window -
     * Preferences - Java - Code Style - Code Templates
     
    */
    public class OpinionDAO
    {

        
    public int addOpinion(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();
                
    int carInfoId = opinion.getCarInfoId();
                
    int activityId=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");
                
    int opinionId=-1;
                
    while(rs.next())
                {
                    opinionId
    =rs.getInt(1);
                }
                
    return opinionId;
            } 
    catch (Exception e)
            {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            } 
    finally
            {

                
    if (rs != null)
                {
                    
    try
                    {
                        rs.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    rs 
    = null;
                }
                
    if (st != null)
                {
                    
    try
                    {
                        st.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    st 
    = null;
                }
                
    if (con != null)
                {
                    
    try
                    {
                        con.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    con 
    = null;
                }

            }
            
    return -1;
        }

        
    public void updateOpinion(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();
                
    int opinionId = opinion.getOpinionId();
                String name 
    = opinion.getName();
                String department 
    = opinion.getDepartment();
                String receiveTime 
    = opinion.getReceiveTime();
                String dealTime 
    = opinion.getDealTime();
                String content 
    = opinion.getContent();
                
    int carInfoId = opinion.getCarInfoId();
                
    int activityId=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 block
                e.printStackTrace();
            } 
    finally
            {

                
    if (st != null)
                {
                    
    try
                    {
                        st.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    st 
    = null;
                }
                
    if (con != null)
                {
                    
    try
                    {
                        con.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    con 
    = null;
                }

            }

        }

        
    public List getOpinions(int carInfoId)
        {
            Connection con 
    = null;
            Statement st 
    = null//創建Statement對象
            ResultSet rs = null;
            List opinions 
    = new ArrayList();
            
    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 
    = new Opinion();
                    opinion.setOpinionId(rs.getInt(
    "opinionId"));
                    opinion.setName(rs.getString(
    "name"));
                    opinion.setDepartment(rs.getString(
    "department"));
                    
                    Timestamp timee 
    = rs.getTimestamp("receiveTime");
                    SimpleDateFormat myFormat 
    = new SimpleDateFormat(
                            
    "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);
                }
                
    return opinions;
                
    //輸出被查詢的情況
            } catch (Exception e)
            {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            } 
    finally
            {

                
    if (rs != null)
                {
                    
    try
                    {
                        rs.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    rs 
    = null;
                }
                
    if (st != null)
                {
                    
    try
                    {
                        st.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    st 
    = null;
                }
                
    if (con != null)
                {
                    
    try
                    {
                        con.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    con 
    = null;
                }

            }
            
    return null;
        }
        
        
    public Opinion getOpinion(int carInfoId,int activityId)
        {
            Connection con 
    = null;
            Statement st 
    = null//創建Statement對象
            ResultSet rs = null;
            Opinion opinion
    =new Opinion();
            
    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"));
                }
                
    return opinion;
                
    //輸出被查詢的情況
            } catch (Exception e)
            {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            } 
    finally
            {

                
    if (rs != null)
                {
                    
    try
                    {
                        rs.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    rs 
    = null;
                }
                
    if (st != null)
                {
                    
    try
                    {
                        st.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    st 
    = null;
                }
                
    if (con != null)
                {
                    
    try
                    {
                        con.close();
                    } 
    catch (SQLException e1)
                    {
                        
    // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                    con 
    = null;
                }

            }
            
    return opinion;
        }
    }



    posted on 2007-07-31 09:40 我為J狂 閱讀(3731) 評論(0)  編輯  收藏 所屬分類: DataBase

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    常用鏈接

    留言簿(11)

    隨筆分類(48)

    文章分類(29)

    常去逛逛

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲v高清理论电影| 东方aⅴ免费观看久久av| 亚洲成人中文字幕| 天堂亚洲免费视频| 成人免费无码大片a毛片| 久久青草国产免费观看| 春意影院午夜爽爽爽免费| 亚洲综合av一区二区三区不卡| 亚洲韩国—中文字幕| 中文字幕中韩乱码亚洲大片| 国产特级淫片免费看| 成年在线观看免费人视频草莓| 免费A级毛片无码A∨免费| 国产精品免费无遮挡无码永久视频| j8又粗又长又硬又爽免费视频| 亚洲国产精品无码久久九九大片| 亚洲成a人片在线观| 亚洲高清免费在线观看| 亚洲国产精品国自产拍AV| 久久伊人亚洲AV无码网站| 亚洲国产精品成人网址天堂| 香蕉高清免费永久在线视频| 久久久久国色AV免费观看性色| 69xx免费观看视频| 最近免费视频中文字幕大全| 免费观看成人久久网免费观看| 国产真人无码作爱免费视频| 国产97视频人人做人人爱免费| 午夜在线免费视频| 日日摸夜夜添夜夜免费视频| 日韩在线一区二区三区免费视频 | 97在线视频免费播放| 久9这里精品免费视频| 免费人成网站在线观看不卡| 精品国产麻豆免费人成网站| 日韩免费高清播放器| 国产一区二区免费视频| 亚洲免费在线视频| 91高清免费国产自产| 日韩精品无码区免费专区| 成人五级毛片免费播放|