[opencms-dev] null?

Mayur Solanki mayur at inflibnet.ac.in
Sat Oct 19 11:44:54 CEST 2002


Hello,

   Connceted MySQL in OpenCms well.
   My JDBC - MySQL connectivity works well but small problem arise...

   When I fetched the data from table (here "test").....
   Definite I found the dataset(records) but I also found in the front of template "null".
   I don't guess it!

   I fetched the dataset in template via Object, my sample java code is here.

 ////////    javacode //////////////////  
import com.opencms.file.*;
import com.opencms.core.*;
import com.opencms.template.*;
import com.opencms.defaults.*;
import com.opencms.file.mySql.*;

import java.sql.*;
import java.lang.*;
import java.util.*;

public class con extends CmsXmlTemplate
{

      public Object getDataset1(CmsObject cms, String tagcontent, 
                  A_CmsXmlContent doc, Object userObject)
                        throws CmsException {
            

            Connection con1 = null;
            PreparedStatement statement1 = null;
            ResultSet res1 = null;
            String poolname1 = "jdbc:opencmspool:mysql";
            String ret1 = null;
            String f2,f3,f4 = null;
            String row1 = null;
            final String SELECT = "select * from test";

            CmsXmlTemplateFile template1 = (CmsXmlTemplateFile)doc;

            try {
                  con1 = DriverManager.getConnection(poolname1);
                  statement1 = con1.prepareStatement(SELECT);
                  res1 = statement1.executeQuery();
      
                  while(res1.next()){
                        // read the items from the resultset
                        f2 = res1.getString(1);
                        f3 = res1.getString(2);
                        f4 = res1.getString(3);

                        template1.setData("name", f2);
                        template1.setData("email", f3);
                        template1.setData("phone", f4);

                        row1 = template1.getProcessedDataValue("row1");
                        ret1= ret1 + row1;
                  }
            }catch(SQLException e) {
                  // exception-handling
            }finally{
                  try{
                        res1.close();
                  }catch (Exception exc) {
                        // ignore this exception
                  }
      
                  try{
                        statement1.close();
                  } catch(Exception exc) {
                        // ignore the exception
                  }
      
                  try{
                        con1.close();
                  } catch(Exception exc) {
                        // ignore the exception
                  }
              }

              return ret1;
      }


}

 /////////////   End javacode  ////////////////////////

I have already "test" table with three fields :  1) name  2) email  3) phone (All are String).

Please give me ideas that when I go wrong!.... Advanced thanks....



M. Solanki.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20021019/672de3ee/attachment.htm>


More information about the opencms-dev mailing list