2012-01-15 19 views
0

ZKossで日付ボックス形式を変換する際に問題があります。次のようにログ出力は次のようになります。日付を選択するZKエラー

input? 
Fri Jan 04 00:00:00 UTC 2002choosing date 
test1 
org.postgresql.util.PSQLException: ERROR: syntax error at or near "Jan" 
    Position: 49 
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2096) 
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1829) 
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257) 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:510) 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386) 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271) 
    at controller.jurnal.jurnalDAO.getLKeuangan(jurnalDAO.java:46) 

//error ommited 

これは私のコントローラクラス

public class JournalController extends GenericForwardComposer { 

    private Listbox listlk; 
    private Datebox datebox; 
    private koneksi k; 
    private Connection c; 
    private SimpleDateFormat sdf; 
    private Button pilih; 

    public JournalController() { 
    } 

    @Override 
    public void doAfterCompose(Component comp) throws Exception { 
     super.doAfterCompose(comp); 

    } 

    public void onClick$pilih() throws Exception, SQLException { 
     try { 
      getListlk(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    public void getListlk() { 
     try { 

      Date dates = datebox.getValue(); 

      System.out.println("input?"); 
      System.out.println(dates + "choosing date"); 

      koneksi k = new koneksi(); 

      jurnalDAO jd = new jurnalDAO(k.getConnection(), dates); 
      List<Jurnal_tbl> ltsu = jd.getLKeuangan(); 
      listlk.setModel(new ListModelList(ltsu, true)); 

      listlk.setItemRenderer(new ListitemRenderer() { 

       public void render(Listitem lstm, Object o) throws Exception { 
        Jurnal_tbl jt = (Jurnal_tbl) o; 
        SimpleDateFormat sdf; 
        sdf = new SimpleDateFormat("yyyy-MM-dd"); 
        String tanggal = sdf.format(jt.getTanggal()); 

        new Listcell(jt.getKode()).setParent(lstm); 
        new Listcell(jt.getTransaksi()).setParent(lstm); 
        new Listcell(tanggal); 
        new Listcell(jt.getAkun()).setParent(lstm); 
        new Listcell(jt.getDeskripsi()).setParent(lstm); 
        new Listcell(jt.getDC()).setParent(lstm); 
        new Listcell(Double.toString(jt.getAmount())).setParent(lstm); 
        new Listcell(jt.getItem()).setParent(lstm); 

        //  System.out.println("test keluar" + tanggal + jt); 
       } 
      }); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } finally { 
      k.closeConnection(); 
     } 
    } 
} 

マイDataAccessObjectクラスです:

public class jurnalDAO { 

    private Connection conn; 
    private Date tanggal; 

    // private String pilihbulan; 
// private String pilihtahun; 
// JournalController lkc = new JournalController(); 
    public jurnalDAO(Connection conn, Date dates) { 
     this.conn = conn; 
     this.tanggal = dates; 
    } 

    public List<Jurnal_tbl> getLKeuangan() throws SQLException, Exception { 
     PreparedStatement ps = null; 

     //  JournalController lkc = new JournalController(); 

     try { 
      List<Jurnal_tbl> llk = new ArrayList<Jurnal_tbl>(); 
      System.out.println("test1"); 
      String sql = "select * from public.jurnal where tanggal = " + tanggal; 
      ps = conn.prepareStatement(sql); 
      ResultSet rs = ps.executeQuery(); 
      while (rs.next()) { 
       llk.add(new Jurnal_tbl(rs.getString("kode"), rs.getString("transaksi"), rs.getDate("tanggal"), rs.getString("akun"), rs.getString("Desc"), rs.getString("dc"), rs.getDouble("amt"), rs.getString("item"))); 
      } 

      rs.close(); 
      return llk; 
     } finally{ 
     } 
    } 
} 

そして、私の最後に、私のZULのページ:

<window title="Untitled Journal" width="auto" height="auto" border="" apply="controller.jurnal.JournalController"> 

         <grid> 
          <rows> 
           <row> 
            <hlayout> 
             <div> 
              <datebox id="datebox" cols="16" format="yyyy-MM-dd" mold="rounded"/> 
              <button id="pilih" label="pilih"/> 
              <button id="cetak" label="Cetak" image="images/Print.png"/> 
             </div> 
            </hlayout> 
           </row> 
          </rows> 
         </grid> 
         <listbox id="Listlk" > 
          <listhead> 
           <listheader label="Kode Jurnal"/> 
           <listheader label="No Transaksi"/> 
           <listheader label="Tanggal"/> 
           <listheader label="Account Number"/> 
           <listheader label="Deskripsi"/> 
           <listheader label="Debit/Credit"/> 
           <listheader label="Amount"/> 
           <listheader label="Item No"/> 
          </listhead> 
         </listbox> 
        </window> 

datebox.getValue()がjan 04 2002を返すときに、日付の書式を変換できません。書式を(yyyy-MM-dd)にします。

助けてくれてありがとう:

+0

あなたのテーブルスキーマとどのようにあなたがそれを保存を提供することができT.T – aulia

+0

私を助けてください? データを保存するための問題ではなく、データの読み込みに問題があると思います。 – TonyQ

答えて

0

これはZKの問題ではありません。 このコードは、あなたの問題です:

String sql = "select * from public.jurnal where tanggal = " + tang gal; 

あなたはあなたが持っていた日付のデフォルト日付のプレゼンテーションを与えるjava.util.Date#のtoString()の変換を行います。

代わりに、あなたは、SQL文のパラメータを入れて、それが価値だ設定する必要があります。

String sql = "select * from public.jurnal where tanggal = :myDate" 
preparedCall = conn.prepareCall(sql); 
preparedCall.setDate(":myDate", tanggal); 
ResultSet rs = preparedCall.executeQuery(); 
関連する問題