alexa-tracking
Selamat Guest, Agan dapat mencoba tampilan baru KASKUS Masih Kangen Tampilan Sebelumnya
Kategori
Kategori
1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/5be2a5a65c7798690c8b4567/netbeans

netbeans

didatabase tanggal tipenya date. tapi coding ini kalo dirun keluarnya "tabel salah". kalo tanggal tipenya ane ganti varchar, tabelnya bisa muncul. jadi codingnya apa yang diganti kak kalo tipenya tetap mau date.

private void table(){
    
        DefaultTableModel tb=new DefaultTableModel();
        tb.addColumn("KODE KATEGORI");
        tb.addColumn("KATEGORI");
        tb.addColumn("TANGGAL");
        
        try{
            int i=1;
            Statement stat=(Statement)conek.GetConnection().createStatement();
            res=stat.executeQuery("select*from input");
            while(res.next())
            {
                tb.addRow(new Object[]{
                    (""+i++),
                    res.getString(1),
                    res.getString(2),
                    res.getString(3) 
                });
                table.setModel(tb);
            }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null,"tabel salah");
        }
        
    }
Urutan Terlama
Quote:

coba getDate()
Code:
while(res.next()){
tb.addRow(new Object[]{
res.getString(1),
res.getString(2),
res.getDate(3),
});
}
table.setModel(tb);

Balasan post 762786153
Quote:


tabel salah kak. tipenya udah diganti date, codingnya juga udah diganti getDate
Balasan post velianoviyanti
Quote:


kemungkinan disini salahnya
Code:
Statement stat=(Statement)conek.GetConnection().createStatement();
res=stat.executeQuery("select*from input");

karena ane gk tau conek itu object apa.
dibagian itu harusnya semacam gini

Code:
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/NAMADB","NAMAUSER","USERPASSWD");
Statement stat = con.createStatement();
ResultSet res = stat.executeQuery("select * from input");
while(res.next()){..............
Balasan post 762786153
Quote:


ga ada masalah disitunya kok kak. conek itu nama java class yang aku buat. databasenya connect kalo tanggal didatabase typenya diganti varchar, terus getDatenya diganti jadi getString
Balasan post velianoviyanti
Quote:

coba

Code:
}catch(Exception e){
e.printStackTrace();
}


kirim output stacktrace kesini.
Balasan post 762786153
Quote:


java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ResultSetRow.getDateFast(ResultSetRow.java:141)
at com.mysql.jdbc.ByteArrayRow.getDateFast(ByteArrayRow.java:238)
at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2211)
at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2173)
at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2238)
at input.table(input.java:53)
at input.<init>(input.java:34)
at input$6.run(input.java:304)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:745)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:706)
at java.awt.EventQueue$3.run(EventQueue.java:704)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:715)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Balasan post velianoviyanti
Quote:
Nol semua tuh emoticon-Malu

Balasan post velianoviyanti
Quote:

'0000-00-00' gk bisa diconvert ke java.sql.Date jadi ubah querynya misal gini
Code:
res = stat.executeQuery("select kode,kategori,case when tanggal='0000-00-00' then null else tanggal end from input");


Diubah oleh 762786153
Balasan post 762786153
Quote:


belum bisa gan, tapi nanti aja diurusnya.
agan tau ga, source code mouse clicked table untuk jcalendar biar bisa nampil ditext field?


×
GDP Network
Copyright © 2018, Kaskus Networks, PT Darta Media Indonesia.
Ikuti KASKUS di