mysql - ORA-01843 error found in netbeans while injecting sql query -


data entered netbeans form not been able insert database table . error found

ora-01843 not valid month found occurs .

following code showing error under submit button ,

 private void submitnewequipactionperformed(java.awt.event.actionevent evt) {                                                string status="park";    string type_id=getid(typelist.getselecteditem().tostring()) ;      calendar cal = new gregoriancalendar();     int month=cal.get(calendar.month);     int day=cal.get(calendar.day_of_month);     int year=cal.get(calendar.year);     system.out.print(cal.get(calendar.date));     system.out.print(month+1);     system.out.print(year);      simpledateformat sdf = new simpledateformat((day)+"/"+(month+1)+"/"+year);     //system.out.print(sdf.format(cal.gettime()).tostring().tostring());         try {               statement stmt=(statement)conn.createstatement();              string sql="insert eqp (id, eqp_type, name, status,make,creator,created)values('"+id.gettext()+"','"+type_id+"','"+name.gettext()+"','"+status+"','"+make.gettext()+"','"+uname+"','"+sdf.format(cal.gettime())+"')";              system.out.println(sdf.format(cal.gettime()));             stmt.executeupdate(sql);           } catch (exception e) {             joptionpane.showmessagedialog(null, e.getmessage() ,"error", 2);         } {      }       // todo add handling code here:     }    

you building date format dd/mm/yyyy format below

 simpledateformat sdf = new simpledateformat((day)+"/"+(month+1)+"/"+year); 

then passing string variable in query enclosed ', should convert date format to_date function

hope using oracle , created column date datatype try query

 string sql="insert eqp (id, eqp_type, name, status,make,creator,created)  values('"+id.gettext()+"','"+type_id+"','"+name.gettext()+"','"+status+"','"+make.gettext() +"','"+uname+"',to_date('"+sdf.format(cal.gettime())+"','dd/mm/yyyy')"; 

here specify date passing in dd/mm/yyyy format.

fiddle

note: try use parameterized queries avoid sqlinjection


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -