0

how to deal with datetime

asked 2013-07-25 01:58:16 +0800

susu gravatar image susu
11 2

why when i deal with date, the error message of
"class java.util.Date cannot be converted to class java.sql.Date." will comeout..how to deal with it

delete flag offensive retag edit

Comments

about a component or variable casting ??

your code please

progamerdotcom ( 2013-07-25 04:33:35 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-07-25 05:16:04 +0800

susu gravatar image susu
11 2

-- this is my file.zul

<zk>

<style src="/css/zkMySclass.css"/>
<window id="wdwAppuserMaint"  mode="modal" style="background:gray " border="normal" width="80%" closable="true" 
action="show: slideDown" xmlns:n="native" apply ="mycom.zk.zapp.mt.Appuser.AppuserMaintCtlr" onCreate="onCreate();">


<zscript><![CDATA[
        import mycom.util.DateUtil;
        import mycom.zk.util.*;     
        import mycom.db.dao.AppuserInfo;
        import mycom.db.dao.AppuserSQL;
        import mycom.zk.base.*;

        AppuserInfo appuser = wdwAppuserMaint$composer.getAppuserInfo();

        void onCreate()
        {
            ZkGuiUtil.setNoEmptyBgColorFields(wdwAppuserMaint);
        }
]]></zscript>


        <caption label="${lbl:name('User Maintenance')}"></caption>

        <grid id="sCriteria" span='true'>
            <columns >

                <column hflex="13"  align="left" />
                <column hflex="min" align="center" />
                <column hflex="35"  align="left" />
                <column hflex="13"  align="left" />
                <column hflex="min" align="center" />
                <column hflex="35"  align="left" />


            </columns>
            <rows >

                <row>
                    <label value="${lbl:name('User Id *')}"  sclass="highlight"/>
                    <span class="req"></span>
                    <textbox id="txtUSR_ID"    width="80%" value="@{appuser.USR_ID}" readonly="false"
                    constraint="" />

                    <label value="${lbl:name('User Enabled *')}" /> 
                         <span class="req"></span>
                            <combobox id="cbxUSR_ACCT_ENABLED" value="@{appuser.USR_ACCT_ENABLED}" width="80%">
                              <comboitem label="Yes" value="Y"/>
                               <comboitem label="No" value="N"/>
                            </combobox>
                </row>  
                <row>

                    <label value="${lbl:name('User Name *')}" />
                    <span class="req"></span>
                    <textbox id="txtUSR_FIRST_NAME" width="80%" value="@{appuser.USR_FIRST_NAME}" readonly="false"
                    constraint="" onChange='' />

                    <label value="${lbl:name('Expired Date')}" />
                    <span class="req"></span>
                    <datebox id="dbxUSR_ID_EXP_DATE" width="80%" value="@{appuser.USR_ID_EXP_DATE}" readonly="false"
                     onChange='' />
                </row>  
                <row>

                    <label value="${lbl:name('Password *')}" />
                    <span class="req"></span>
                    <textbox id="txtUSR_PASSWORD" type="password" value="@{appuser.USR_PASSWORD}"   width="80%" readonly="false"
                    />
                    <span class="req"></span>
                    <span class="req"></span>
                    <span class="req"></span>

        </row>
                <row>   
                    <label value="${lbl:name('Password Hint')}" />
                    <span class="req"></span>
                    <cell colspan='5'>
                    <textbox id="txtUSR_PASSWORD_HINT" value="@{appuser.USR_PASSWORD_HINT}"   width="80%" readonly="false"
                    constraint="" onChange='' />
                    </cell>


                </row>  
                <row>   
                    <label value="${lbl:name('Password Expired( Day )')}" />
                    <span class="req"></span>
                    <textbox id="txtUSR_PWD_EXPIRED_DAY" value="@{appuser.USR_PWD_EXPIRED_DAY}" width="80%" readonly="false"
                    constraint="" onChange='' />
                    <span class="req"></span>
                    <span class="req"></span>
                    <span class="req"></span>

                </row>  
                <row>
                    <label value="${lbl:name('Company *')}" />
                    <span class="req"></span>
                    <combobox id="cbxUSR_COMP" value="@{appuser.USR_COMP}" width="80%">
                              <comboitem label="000- GALAXY Group SDN BHD" value="000"/>
                              <comboitem label="FGHQ- FG HQ" value="FGHQ"/>
                            </combobox>
                    <span class="req"></span>
                    <span class="req"></span>
                    <span class="req"></span>
                </row>  
                <row>

                    <label value="${lbl:name('Menu Profile *')}" /> 
                         <span class="req"></span>
                            <combobox id="cbxUSR_PRFL_CODE" value="@{appuser.USR_PRFL_CODE}" width="80%">
                              <comboitem label="BASE - Base Menu" value="BASE"/>
                              <comboitem label="GLXHQ - GLX HQ" value="GLXHQ"/>
                              <comboitem label="GLXMR - GALAXY MERCHANT OR OUTLET" value="GLXMR"/>
                              <comboitem label="Mng - Manager Menu" value="Mng"/>
                            </combobox>

                    <label value="${lbl:name('Prefered Language')}" /> 
                         <span class="req"></span>
                            <combobox id="cbxUSR_LANGUAGE" value="@{appuser.USR_LANGUAGE}" width="80%">
                              <comboitem label="0 - English" value="0"/>
                              <comboitem label="1 - Simplified Chinese" value="1"/>
                              <comboitem label="2 - Traditional Chinese" value="2"/>
                              <comboitem label="3 - Bahasa Melayu" value="3"/>
                              <comboitem label="4 - Bahasa Indonesia" value="4"/>
                              <comboitem label="5 - Japanese" value="5"/>
                              <comboitem label="6 - Thai" value="6"/>
                              <comboitem label="7 - Arabic" value="7"/>
                            </combobox>

                </row>
                <row>

                    <label value="${lbl:name('User Group *')}" /> 
                         <span class="req"></span>
                            <combobox id="cbxUSR_GRP" value="@{appuser.USR_GROUP}" width="80%">
                              <comboitem label="AG - Agent" value="AG"/>
                             <comboitem label="MB - Member" value="MB"/>
                             <comboitem label="MC - Merchant" value="MC"/>
                              <comboitem label="SL - Sales" value="SL"/>
                              <comboitem label="FN - Finance" value="FN"/>
                              <comboitem label="SA - System Admin" value="SA"/>
                              <comboitem label="AD - Admin" value="AD"/>
                              <comboitem label="GN - General" value="GN"/>
                            </combobox>

                    <label value="${lbl:name('User Code')}" /> 
                         <span class="req"></span>
                         <textbox id="txtUSR_CODE" value=""   width="80%" readonly="false"
                    constraint="" onChange='' />


                </row>
                <row>

                    <label value="${lbl:name('Superior')}" /> 
                         <span class="req"></span>
                             <textbox id="txtUSR_SUPERIOR" value="@{appuser.USR_SUPERIOR}" width="80%" readonly="false"
                    constraint="" onChange='' />    

                    <label value="${lbl:name('User Level')}" /> 
                         <span class="req"></span>
                            <combobox id="cbxUSR_LEVEL" value="@{appuser.USR_LEVEL}" width="80%">
                              <comboitem label="01 - Non-Executive" value="01"/>
                              <comboitem label="02 - Executive" value="02"/>
                              <comboitem label="03 - Manager" value="03"/>
                              <comboitem label="04 - Senior Manager" value="04"/>
                            </combobox>

                </row>
                <row>

                    <label value="${lbl:name('Telephone')}" /> 
                         <span class="req"></span>
                             <textbox id="txtUSR_PHONE_NBR" value="@{appuser.USR_PHONE_NBR}"   width="80%" readonly="false"
                    constraint="" onChange='' />    

                    <label value="${lbl:name('E-Mail')}" /> 
                         <span class="req"></span>
                             <textbox id="txtUSR_EMAIL" value="@{appuser.USR_EMAIL}"   width="80%" readonly="false"
                    constraint="/.+@.+\.[a-z]+/: Please enter an e-mail address" onChange='' />    

                </row>
                <row>

                    <label value="${lbl:name('Last Login Date')}" /> 
                         <span class="req"></span>
                             <datebox id="dbxUSR_LAST_LOGIN_DATE" value="@{appuser.USR_LAST_LOGIN_DATE}" onCreate="self.value = new Date()"  
                             width="80%" readonly="true"
                     />    

                    <label value="${lbl:name('Last Password Changed Date')}" /> 
                         <span class="req"></span>
                             <datebox id="dbxUSR_PWD_LAST_CHG_DATE" value="@{appuser.USR_PWD_LAST_CHG_DATE}" width="80%" readonly="false"
                    constraint="" onChange='' />    

                </row>
                <row spans='50'>
                    <div align='right'>
                        <button id="btnSave" label="${lbl:name('Save')}" width="80px" autodisable="self"/>
                        <button id="btnCancel" label="${lbl:name('Cancel')}" width="80px" autodisable="self"/>
                    </div>
                </row>
            </rows>
        </grid>


    <div id="div_maint"/>
    <zscript><![CDATA[
    String MaintMode = (String) this.arg.get(ZkConstants.MaintMode);

    if (MaintMode != null && MaintMode.equals(ZkConstants.MaintModeEdit))
    {
        txtUSR_ID.setReadonly(true);


    }
    if (MaintMode != null && MaintMode.equals(ZkConstants.MaintModeView))
    {
        ZkGuiUtil.disabledComponents(wdwAppuserMaint, true);
        btnSave.setVisible(false);
    }

]]></zscript>

</window>

</zk>

-- this is my controller

/**
* ESMART Access Sdn Bhd * Copyright (C) 2013 * All rights reserved.


/ /*
* Synopsis: Appuser Maint


  • Written: Suraya Md Amin 2013-07-23 15:45:00

  • Revised: Date/ Name/ Synopsis.


*/

package mycom.zk.zapp.mt.Appuser;

import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map;

import mycom.util.DateUtil; import mycom.zk.base.ZkConstants; import mycom.zk.util.PageUtil; import mycom.zk.util.ZkGuiUtil;

import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.select.SelectorComposer; import org.zkoss.zk.ui.select.annotation.Listen; import org.zkoss.zul.Window;

import mycom.db.dao.AppuserInfo; import mycom.db.dao.AppuserSQL;

public class AppuserMaintCtlr extends SelectorComposer <window> { private static final long serialVersionUID = 201307231516L;

private Map arg = null; 
private Window wdwAppuserMaint;
private AppuserSQL appuserSQL = null;
private String MaintMode = null;



@Override
public void doBeforeComposeChildren(Window wdw) throws Exception
{
    super.doBeforeComposeChildren(wdw);
    wdwAppuserMaint = wdw;

    this.arg = Executions.getCurrent().getArg();
    jInit();
    // System.out.println("ImpfilectrlMaintCtlr=" + this.arg.get("IMP_FILE_NAME"));
}

@Override
public void doAfterCompose(Window wdw) throws Exception
{
    super.doAfterCompose(wdw);

    //ZkGuiUtil.setNoEmptyBgColorFields(wdw);
    // init
}

private void jInit() throws Exception
{
    appuserSQL = new AppuserSQL();
    MaintMode = (String) this.arg.get(ZkConstants.MaintMode);
    if (MaintMode != null && 
            (MaintMode.equals(ZkConstants.MaintModeEdit)
                    || MaintMode.equals(ZkConstants.MaintModeView) || MaintMode.equals(ZkConstants.MaintModeView )))
    {
        appuserSQL.setUSR_ID((String)arg.get("USR_ID"));
        //datalogSQL.setDAT_DATE(DateUtil.parseDatetime((String) arg.get("DAT_DATE")));
        //appuserSQL.setUSR_ID_EXP_DATE(DateUtil.parseDatetime((String) arg.get("USR_ID_EXP_DATE")));

        if (appuserSQL.getByKey() == 0)
        {
            ZkGuiUtil.showInformation(PageUtil.getPrompt("Record does not exist"));
        }

    }
}

public AppuserInfo getAppuserInfo()
{
    return (appuserSQL);
}

@Listen("onClick = #btnSave")
public void save()
{

    processSave();

}

@Listen("onClick = #btnCancel")
public void cancel()
{
    wdwAppuserMaint.onClose();
}


private void processSave()
{
    if (MaintMode != null && MaintMode.equals(ZkConstants.MaintModeAdd))
    {

        addNewRecord();
    }
    else
    if (MaintMode != null && MaintMode.equals(ZkConstants.MaintModeEdit))
    {
        editRecord();
    }

}



private void editRecord()
{
    AppuserMaintEditRec editRec = new AppuserMaintEditRec();
    appuserSQL.setLAST_OPR(PageUtil.getUserLogin().getUSR_ID());
    editRec.saveRecords(appuserSQL);
    if (editRec.hasError() == false)
    {
        ZkGuiUtil.showInformation(PageUtil.getPrompt("Record being updated successfully"));
        wdwAppuserMaint.onClose();
    Component wdwAppuserSearch = Executions.getCurrent().getDesktop().getPage("pageAppuserSearch").getFellow("wdwAppuserSearch");
    if (wdwAppuserSearch != null)
    {
        Events.postEvent(Events.ON_CLICK, wdwAppuserSearch, ZkConstants.refreshCurrentPage);
    }
    }
    else
    {
        ZkGuiUtil.showInfo2User(wdwAppuserMaint, editRec.getErrors());
    }
  }

private static final String AppuserMaint = "/zapp/mt/AppuserMaint.zul";
private void addNewRecord()
{

    AppuserMaintAddRec saveNewRec = new AppuserMaintAddRec();
    appuserSQL.setLAST_OPR(PageUtil.getUserLogin().getUSR_ID());
    saveNewRec.saveRecords(appuserSQL);


    if (saveNewRec.hasError() == false)
    {

        wdwAppuserMaint.onClose();

    Component wdwAppuserSearch = Executions.getCurrent().getDesktop().getPage("pageAppuserSearch").getFellow("wdwAppuserSearch");
    if (wdwAppuserSearch != null)
    {
        Events.postEvent(Events.ON_CLICK, wdwAppuserSearch, ZkConstants.refreshCurrentPage);

        Map<String, String> map = new HashMap<String, String>();
        map.put(ZkConstants.MaintMode, ZkConstants.MaintModeAdd);
        Executions.createComponents(AppuserMaint, wdwAppuserSearch, map);

        ZkGuiUtil.showInformation(PageUtil.getPrompt("Record being saved successfully"));
    }

    }
    else
    {
        //debug(saveNewRec.getErrors().toString());
        ZkGuiUtil.showInfo2User(wdwAppuserMaint, saveNewRec.getErrors());
    }
}

// private boolean DEBUG = true; // private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // private void debug(String msg) // { // if (DEBUG) // { // java.util.Date dt = new java.util.Date();
// System.out.println(sdf.format(dt) + " " + msg); // } // }

}

--this is my adddata.java

/** * ESMART Access Sdn Bhd * Copyright (C) 2013 * All rights reserved.


/ /*
* Synopsis: Appuser Maint




  • Written: Suraya Md Amin 2013-07-23

  • Revised: Date / Name / Synopsis


*/

package mycom.zk.zapp.mt.Appuser;

import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.Vector;

import mycom.db.conn.DSCreator; import mycom.db.dao.DataLogger; import mycom.db.util.ConnUtil; import mycom.db.dao.AppuserInfo; import mycom.db.dao.AppuserSQL;

public class AppuserMaintAddRec { private static final String FUNCTION = "Application User";

private ArrayList<String> errList = new ArrayList<String>();
private Connection conn = null;
private AppuserSQL appuserSQL;
private AppuserInfo appuserInfo;

private void jInit() throws SQLException
{
    appuserSQL = new AppuserSQL(conn);
}

public void saveRecords(AppuserInfo _AppuserInfo)
{
    appuserInfo = _AppuserInfo;
    try
    {
        openConnection();
        jInit();

        start();
        conn.commit();

    }
    catch (Throwable t)
    {
        errList.add(t.toString());
        try
        {
            conn.rollback();
        }
        catch (Exception e)
        {
        }
        t.printStackTrace();
    }
    finally
    {
        closeConnection();
    }
}

private void start() throws Exception
{ 

    if (verifyInputData() == false)
    {
        return;
    }

    appuserSQL.setVObject((Vector)appuserInfo.getVObject().clone());
    if (appuserSQL.getByKey() > 0)
    {
        errList.add("The data already exist");
    }
    else
    {
        appuserSQL.insert();

        // audit log
    DataLogger dataLogger = new DataLogger(conn);
    dataLogger.setFunctionName(FUNCTION);
    dataLogger.logInsertNewRecord(appuserSQL);

    }
}

private boolean verifyInputData()
{
    boolean rt = true;
    if ((appuserInfo.getUSR_ID().trim().length() == 0))

    {

        rt = false;
    }
    if(appuserInfo.getUSR_ACCT_ENABLED().trim().length() == 0)
    {

        rt = false;
    }
    if(appuserInfo.getUSR_COMP().trim().length() == 0)
    {

        rt = false;
    }
    if(appuserInfo.getUSR_GROUP().trim().length() == 0)
    {

        rt = false;
    }
    if(appuserInfo.getUSR_PRFL_CODE().trim().length() == 0)
    {
        errList.add(" Please fill in the field with star sign");
        rt = false;
    }

    return (rt);
}

public boolean hasError()
{
    return (errList.size() > 0);
}

public ArrayList<String> getErrors()
{
    return (errList);
}

protected void closeConnection()
{
    ConnUtil.close(conn);
    conn = null;

}

protected void openConnection() throws SQLException
{
    conn = DSCreator.getConnection();
    conn.setAutoCommit(false);
}

}

link publish delete flag offensive edit

Comments

When you asking any question please ask questions in question section..You can edit your question rather than posting in answer section.Second thing copy-paste whole code is not solve your problem any one who is going to help you not read your code rather than give some small demo

sjoshi ( 2013-07-25 07:52:40 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-07-25 01:58:16 +0800

Seen: 20 times

Last updated: Jul 25 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More