<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)

    常去逛逛

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲美女精品视频| 特级aa**毛片免费观看| 毛片免费全部播放一级| 边摸边脱吃奶边高潮视频免费| 久久亚洲高清观看| 免费鲁丝片一级在线观看| 羞羞漫画页面免费入口欢迎你| 国产V亚洲V天堂无码| 啦啦啦www免费视频| 18禁在线无遮挡免费观看网站| 亚洲AV成人一区二区三区在线看| 亚洲第一永久AV网站久久精品男人的天堂AV | 两个人的视频www免费| 亚洲精品无码久久久久久久| www.亚洲精品| 欧美a级成人网站免费| 中文在线观看免费网站| 亚洲日韩国产一区二区三区在线 | 18成禁人视频免费网站| 国产亚洲精品第一综合| 亚洲精品国产成人中文| 亚洲精品无码鲁网中文电影| 青青草国产免费久久久91| 8888四色奇米在线观看免费看| 水蜜桃视频在线观看免费| 亚洲熟妇av一区二区三区下载| 亚洲一区二区三区在线视频| 性感美女视频在线观看免费精品 | 国产美女精品视频免费观看| 99久久久国产精品免费牛牛四川| 免费国产va在线观看| 亚洲最大的成人网站| 亚洲综合视频在线观看| 亚洲av无码av制服另类专区| 亚洲av无码乱码在线观看野外| 一二三四在线播放免费观看中文版视频 | 黄色网址免费观看| 久久久久国产精品免费免费不卡| 免费中文字幕视频| 亚洲AV无码专区在线电影成人 | 污视频在线观看免费|