java - Splitting Object -


i'm implementing interface setobject accept string, int, double etc. data type use in insert statement. when inserting data in database gives me values [a,b,c] [a,b,c] [a,b,c]. how can avoid output?

interface:

public interface callablestatement {     arraylist<object> mylist = new arraylist<>();     public void setobject(arraylist<object> mylist);  }  public class position implements callablestatement {     string departmentname;     string departmenttype;     string departmentdescription;      public position()     {         array();     }      public void array()     {         arraylist<object> mylist = new arraylist<object>();         mylist.add(departmentname);         mylist.add(departmenttype);         mylist.add(departmentdescription);     }       @override     public void setobject(arraylist<object> mylist)      {         string query = "{call insertpositions(?,?,?)}";          try(connection con = dbutil.getconnection(dbtype.mysql);             java.sql.callablestatement cs = con.preparecall(query);)                                     //prepare stored procedure call         {             //setting parameters             cs.setobject(1, mylist.tostring());             cs.setobject(2, mylist.tostring());             cs.setobject(3, mylist.tostring());             cs.executeupdate();         }         catch(sqlexception e)         {             system.err.println("error: "+e.getmessage());             system.err.println("error: "+e.geterrorcode());             system.err.println("error: "+e.getsqlstate());         }     } } 

gui:

private void adddepartmentbtnactionperformed(java.awt.event.actionevent evt) {                                                      string departmentname = tfdepartmentname.gettext();     string departmenttype = tfdepartmenttype.gettext();     string departmentdescription = tfdescription.gettext();      arraylist<object> addpositionslist = new arraylist<object>();     addpositionslist.add(departmentname);     addpositionslist.add(departmenttype);     addpositionslist.add(departmentdescription);      callablestatement cs = new position();     cs.setobject(addpositionslist);  }  

cs.setobject(1, mylist.tostring()); cs.setobject(2, mylist.tostring()); cs.setobject(3, mylist.tostring()); 

but:

mylist.tostring() = [a,b,c] 

so when this, you'll [a,b,c] [a,b,c] [a,b,c] 3 objects.

instead try

cs.setobject(1, mylist.get(0).tostring()); cs.setobject(2, mylist.get(1).tostring()); cs.setobject(3, mylist.get(2).tostring()); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -