title: Mysql table Object List to String Array by System.arraycopy got ArrayStoreException?
body: <p>I am trying example in java with help of Mysql, Hibernate.
  I created 2 tables in Mysql, named table1, table2.
  Each have 3 columns
  <code>table1</code>.<code>rowindex</code>, <code>table1</code>.<code>column1</code>, <code>table1</code>.<code>column2</code>
  <code>table2</code>.<code>rowindex</code>, <code>table2</code>.<code>column1</code>, <code>table2</code>.<code>column2</code></p>
  
  <p>Scene is 
  1. Sometimes table1.column1 value is equal to table2.column2.
  2. It will find by table1.column2 value.</p>
  
  <p>So query I used</p>
  
  <pre><code>SELECT a.column1, b.column1, a.column2, b.column2 FROM table1 a, table2 b where a.column1 = b.column1 and a.column2 ='Mandar';
  </code></pre>
  
  <p>It shows me accurate result in Mysql workbench.
  Then I wrote java program to fetch this result &amp; tried to print it.</p>
  
  <p>I wrote table fetching function as follows:-</p>
  
  <pre><code>protected static List get_combined_two_tables(String string) {
      if (resultList != null) {
          resultList.clear();
      }
      flag_file = filecheckhibernate1(false);
      if (flag_file) {
          session = HibernateUtil.getSessionFactory("hibernate1.cfg.xml").openSession();
          if (session != null) {
              if (session.isOpen() == true) {
                  try {
                      session.beginTransaction();
                  } catch (TransactionException e) {
                      e.printStackTrace();
  
                  } catch (JDBCConnectionException e) {
                      e.printStackTrace();
  
                  }
                  String selectQuery = "SELECT a.column1, b.column1, a.column2, b.column2 FROM table1 a, table2 b where a.column1 = b.column1 and a.column2 =:name";
                  System.out.println("selectQuery = " + selectQuery);
                  Query q = null;
                  try {
                      q = session.createQuery(selectQuery);
                      q.setString("name", "Mandar");
                  } catch (org.hibernate.QueryException e) {
                      e.printStackTrace();
                  }
                  if (q != null) {
                      resultList = q.list();
                      session.getTransaction().commit();
                  }
                  if (session.isOpen()) {
                      session.close();
                  }
  
              }
          }
      }
      return resultList;
  }
  </code></pre>
  
  <p>For print I wrote following function:-</p>
  
  <pre><code>                        List&lt;?&gt; combined_table_List = null;
                      combined_table_List = get_combined_two_tables("Mandar");
                      if(combined_table_List != null) {
                          String[] dest = null;
                          for (int i = 0; i &lt; combined_table_List.size(); i++) {
                                  dest = new String[combined_table_List.get(i).toString().length()];
                                  if(dest != null) {
                                      try {
                                          System.arraycopy(combined_table_List,0,dest,0,combined_table_List.get(i).toString().length());
                                      } catch (Exception e) {
                                          e.printStackTrace();
                                      }
                                          if(Arrays.toString(dest) != null) {
                                               System.out.println("Arrays.toString(dest) ="+Arrays.toString(dest));
                                          }   
                                  }
  
                          }   
                      }
  </code></pre>
  
  <p>When I run program, I got exception as follows:-</p>
  
  <pre><code>java.lang.ArrayStoreException
  at java.lang.System.arraycopy(Native Method)
  at test_db$1.run(test_db.java:132)
  at java.awt.event.InvocationEvent.dispatch(Unknown Source)
  at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
  at java.awt.EventQueue.access$500(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.awt.EventQueue$3.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
  at java.awt.EventQueue.dispatchEvent(Unknown Source)
  at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
  at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
  at java.awt.EventDispatchThread.run(Unknown Source)
  Arrays.toString(dest) =[null, null, null, null, null, null, null, null, 
  null, null, null, null, null, null, null, null, null, null, null, null, 
  null, null, null, null, null, null, null, null]
  </code></pre>
  
  <p>Need help to solve this.</p>