<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狂 閱讀(3732) 評論(0)  編輯  收藏 所屬分類: DataBase

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

    導航

    統計

    常用鏈接

    留言簿(11)

    隨筆分類(48)

    文章分類(29)

    常去逛逛

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲综合久久成人69| 亚洲国产AV一区二区三区四区| 精品熟女少妇av免费久久| 亚洲狠狠狠一区二区三区| 大学生高清一级毛片免费| 一区二区三区在线观看免费| 亚洲欧洲另类春色校园小说| 国产猛烈高潮尖叫视频免费| 永久免费A∨片在线观看| 中文文字幕文字幕亚洲色| 国产精品亚洲不卡一区二区三区 | 亚洲老熟女@TubeumTV| 在线播放免费播放av片| 拍拍拍无挡免费视频网站| 亚洲精品久久无码| 久久久久亚洲av无码专区导航| 日本xxwwxxww在线视频免费| 日韩电影免费在线观看| 国产亚洲精品精品精品| 亚洲第一页在线播放| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 一级毛片免费视频网站| 激情综合亚洲色婷婷五月APP| 最新国产AV无码专区亚洲 | 伊人久久综在合线亚洲2019| 免费jjzz在线播放国产| 120秒男女动态视频免费| 国产精品hd免费观看| 亚洲国产精品无码久久九九大片 | 最近2019中文字幕mv免费看| 99re6在线视频精品免费| 爱情岛论坛亚洲品质自拍视频网站| 亚洲黄色免费在线观看| 亚洲码国产精品高潮在线| 无码专区一va亚洲v专区在线| 久久精品a一国产成人免费网站| 亚洲免费人成在线视频观看 | 成人免费无码大片A毛片抽搐| 久久久久久久99精品免费| www免费插插视频| 青娱乐在线免费观看视频|