java - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : getting a SEVERE: null -
i'm new in programming , want filter data grouped rent date . error
revenuebylocs bt_filteractionperformed severe: null com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'rent_date between '2013-01-01' , '2014-02-02' group rent_date, a.branch_id' @ line 1 @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:39) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:27) @ java.lang.reflect.constructor.newinstance(constructor.java:513) @ com.mysql.jdbc.util.handlenewinstance(util.java:411) @ com.mysql.jdbc.util.getinstance(util.java:386) @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:1052) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3609) @ com.mysql.jdbc.mysqlio.checkerrorpacket(mysqlio.java:3541) @ com.mysql.jdbc.mysqlio.sendcommand(mysqlio.java:2002) @ com.mysql.jdbc.mysqlio.sqlquerydirect(mysqlio.java:2163) @ com.mysql.jdbc.connectionimpl.execsql(connectionimpl.java:2618) @ com.mysql.jdbc.connectionimpl.execsql(connectionimpl.java:2568) @ com.mysql.jdbc.statementimpl.executequery(statementimpl.java:1557) @ revenuebylocs.bt_filteractionperformed(revenuebylocs.java:282) @ revenuebylocs.access$200(revenuebylocs.java:27) @ revenuebylocs$3.actionperformed(revenuebylocs.java:179) @ javax.swing.abstractbutton.fireactionperformed(abstractbutton.java:1995) @ javax.swing.abstractbutton$handler.actionperformed(abstractbutton.java:2318) @ javax.swing.defaultbuttonmodel.fireactionperformed(defaultbuttonmodel.java:387) @ javax.swing.defaultbuttonmodel.setpressed(defaultbuttonmodel.java:242) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(basicbuttonlistener.java:236) @ java.awt.component.processmouseevent(component.java:6267) @ javax.swing.jcomponent.processmouseevent(jcomponent.java:3267) @ java.awt.component.processevent(component.java:6032) @ java.awt.container.processevent(container.java:2041) @ java.awt.component.dispatcheventimpl(component.java:4630) @ java.awt.container.dispatcheventimpl(container.java:2099) @ java.awt.component.dispatchevent(component.java:4460) @ java.awt.lightweightdispatcher.retargetmouseevent(container.java:4577) @ java.awt.lightweightdispatcher.processmouseevent(container.java:4238) @ java.awt.lightweightdispatcher.dispatchevent(container.java:4168) @ java.awt.container.dispatcheventimpl(container.java:2085) @ java.awt.window.dispatcheventimpl(window.java:2478) @ java.awt.component.dispatchevent(component.java:4460) @ java.awt.eventqueue.dispatchevent(eventqueue.java:599) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:269) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:184) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:174) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:169) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:161) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:122)
and here's code
private void bt_filteractionperformed(java.awt.event.actionevent evt) { // todo add handling code here: try { string value1= ((jtextfield)dt_rangeto.getdateeditor().getuicomponent()).gettext(); string value2= ((jtextfield)dt_rangefrom.getdateeditor().getuicomponent()).gettext(); string sql = " select distinct(rent_date) date, branch_name , sum(rent_amount)"+ "from t_rent inner join t_rent_detail b on a.rent_id = "+ "b.rent_id inner join t_branch c on a.branch_id=c.branch_id"+ "where rent_date between '"+value2+"' , '"+value1+"' "+ "group rent_date, a.branch_id "; pst = koneksi.getkoneksi().preparestatement(sql); rs=pst.executequery(sql); tb_revenue.setmodel(dbutils.resultsettotablemodel(rs)); joptionpane.showmessagedialog(null, "filtered"); } catch (sqlexception ex) { logger.getlogger(staff.class.getname()).log(level.severe, null, ex); joptionpane.showmessagedialog(null, "no data"); } }
what did wrong ? can show if input value of rent_date manually . test on mysqlog. here's string tried on mysqlog
select distinct(rent_date) date, branch_name , sum(rent_amount) t_rent inner join t_rent_detail b on a.rent_id = b.rent_id inner join t_branch c on a.branch_id=c.branch_id rent_date between '2013-01-01' , '2014-02-02' group rent_date, a.branch_id
and showing fine. won't work in java . need add ?
oh , 1 more question. want show table this:
date s mrental 2014-01-01 10000 10000 2014-05-05 10000 10000
how can that? (s , m branch_name)
add space before where
(and before from
well)
" rent_date between '"+value2+"' , '"+value1+"' "
Comments
Post a Comment