Good day I’m new with JSP, here the problem,
I just converting the code from SQL to PostgreSQL, but a problem occur
after I change to

DataSource ds   = (DataSource)envCtx.lookup( "jdbc/postgres" );

and add a scheme to the query. By theory it should be ok but it produce this error

    Error accessing StudPractical bean. java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Vector

the code

 vResult = beanPractical.viewSchoolListing(limit, start, searchState, searchKey, searchBy, schoolType, rosID, sem);

Practical Class

public Vector viewSchoolListing(int paramInt1, int paramInt2, String paramString1, String paramString2, String paramString3, String paramString4, String paramString5, String paramString6)


    {
        Statement localStatement = null;
        ResultSet localResultSet = null;
        Vector localVector1 = null;
        Vector localVector2 = null; Vector localVector3 = null; Vector localVector4 = null; Vector localVector5 = null;
        int i = 0;
    String str1 = ""; String str2 = "";
    String str3 = null;
    int j = 0;

    int k = getROSQuota(paramString6);

    paramString2 = escapeQuote(paramString2);
    try
    {
      localStatement = this.conn.createStatement();
      str3 = "SELECT PC_CTR_CODE,PC_CTR_NAME,PC_CTR_ADDR1,PC_CTR_TEL,PC_CTR_CITY FROM SYSTEM.PRACTICAL_CENTER WHERE PC_CTR_STATE = '" + paramString1 + "' ";

      if ((paramString3 != null) && (!paramString3.equals(""))) {
        if (paramString3.equals("Sekolah"))
          str3 = str3 + "AND PC_CTR_NAME LIKE UPPER('%" + paramString2 + "%') ";
        if (paramString3.equals("Bandar")) {
          str3 = str3 + "AND PC_CTR_CITY LIKE UPPER('%" + paramString2 + "%') ";
        }
      }
      if ((paramString4 != null) && (!paramString4.equals(""))) {
        str3 = str3 + "AND PC_CTR_TYPE = '" + paramString4 + "' ";
      }

      str3 = str3 + "AND (SELECT COUNT(1) FROM SYSTEM.ROS_MAIN WHERE PSR_CTR_CODE = PC_CTR_CODE AND PSR_ROS_ID = '" + paramString5 + "' AND PSR_ROS_STATUS = 'APPLY') < " + k;

      str3 = str3 + " ORDER BY PC_CTR_NAME";

      localResultSet = localStatement.executeQuery(str3);
      localVector1 = new Vector();

      if (localResultSet.isBeforeFirst())
      {
        localVector2 = new Vector();
        localVector3 = new Vector();
        localVector4 = new Vector();
        localVector5 = new Vector();

        while (localResultSet.next())
        {
          j++;
          if ((j >= paramInt2) && (j < paramInt2 + paramInt1)) {
            if (localResultSet.getString(1) != null)
              localVector2.add(localResultSet.getString(1));
            else {
              localVector2.add("");
            }
            if (localResultSet.getString(2) != null)
              localVector3.add(localResultSet.getString(2));
            else {
              localVector3.add("");
            }
            if (localResultSet.getString(3) != null) {
              if (localResultSet.getString(5) != null)
                str2 = localResultSet.getString(3) + " " + localResultSet.getString(5);
              else
                str2 = localResultSet.getString(3);
              localVector4.add(str2);
            }
            else {
              localVector4.add("");
            }
            if (localResultSet.getString(4) != null)
              localVector5.add(localResultSet.getString(4));
            else
              localVector5.add("");
          }
        }
        localVector1.add(localVector2);
        localVector1.add(localVector3);
        localVector1.add(localVector4);
        localVector1.add(localVector5);
        if (j > 0)
          localVector1.add(new Integer(j));
      }
      localResultSet.close();
      localStatement.close();
    }
    catch (Exception localException1) {
      i = 1;
      str1 = str1 + localException1.toString();
      localException1.printStackTrace();
    }
    finally {
      try {
        if (localStatement != null)
          localStatement.close();
      }
      catch (Exception localException2) {
      }
    }
    if (i != 0)
    {
      str1 = "StudPractical.viewSchoolListing(): " + str1;
      System.out.println(str1);
      localVector1 = new Vector();
      localVector1.add("An error occured: " + str1);
    }
    return localVector1;
  }

Thank for your help

Member Avatar for LastMitch

Error accessing StudPractical bean. java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Vector

You can read more about what is java.lang.ClassCastException:

http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/ClassCastException.html

To solve this issue:

java.lang.String cannot be cast to java.util.Vector

Read this (it will explain Vector of Strings but a Vector of String[]:

http://stackoverflow.com/questions/9098755/java-lang-string-cannot-be-cast-to-java-lang-string

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.