[opencms-dev] null?
Mayur Solanki
mayur at inflibnet.ac.in
Sat Oct 19 14:46:53 CEST 2002
Hello Richard,
Ok..Sorry for just mistake.
Now my problem is solved.
Thanks a lot.........
Mayur
----- Original Message -----
From: Richard Friedman
To: opencms-dev at www.opencms.org
Sent: Saturday, October 19, 2002 5:15 PM
Subject: RE: [opencms-dev] null?
You initialized ret1 to null (ret1=null;) and within the loop you do ret1 = ret1 + row1. First time throught ret1 is null.
Initialize ret1 = "";
-Rich.
-----Original Message-----
From: owner-opencms-dev at www.opencms.org [mailto:owner-opencms-dev at www.opencms.org] On Behalf Of Mayur Solanki
Sent: Saturday, October 19, 2002 5:45 AM
To: opencms-dev at www.opencms.org
Subject: [opencms-dev] null?
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/398e860c/attachment.htm>
More information about the opencms-dev
mailing list