aspose file tools*
The moose likes Java in General and the fly likes Need Help with XML & ResultSet problem... Urgent Please!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Need Help with XML & ResultSet problem... Urgent Please!!!!!!

sam patel
Ranch Hand

Joined: Jun 13, 2002
Posts: 103
Hi,
I am sorry I have to cross post this,
I have this applet-servlet communication. The servelt does the datbase work and the applet shows
the image on the applet side. I was doing the query in the servlet side, but i want to use the XML to
do DB work and the querys. First I am searching the DB by policynumber. I wrote this class which is ResultSetToXML which
takes the ResultSet and boolean to check if the values are null or not.
My problem occurs when it goes in the ResultSetToXML and creates the /******* root = new Element("Pinfo");*********/
I have tried this code in Application and it works fine.
I am posting one of my class which has the ResultSet and i am passing this ResultSet in the ResultSetToXML.
I am in the begenning stage of the XML. I just want to check if it creates the XML file from this REsultSet.
Any help is greatly appreciated.
Thanks in advance.

//----------------------------------------------------------//
ScanDatabaseAccessor class which is on the Servlet side
//----------------------------------------------------------//
class ScanDatabaseAccessor implements java.io.Serializable{
private Connection dbConnection;
private static InputStream stream;
private PreparedStatement searchPolicy;
private PreparedStatement searchUnmatchAndPolicy;
private PreparedStatement searchImageInfo;
private String xFirstName,
xLastName,
xMiddleName,
xSSN,
xPolicyNumber,
xCompanyCode,
xCoverage,
xInsuredNo;
private java.sql.Date xDOB,
xApplicationDate;

//**************************************
public ResultSetToXML rstx;
//**************************************
public ScanDatabaseAccessor(String dbDriver, String dbURL, String userID, String passwd)
{
String tempStr;
// use println statements to send status messages to web server console
try {
log("ScanDataAccessor init: Start");
log("ScanDataAccessor init: Loading Database Driver: " + dbDriver);
Class.forName(dbDriver);
log("ScanDataAccessor init: Getting a connection to - " + dbURL);
System.out.println("username " +userID);
System.out.println("password "+passwd);
dbConnection = DriverManager.getConnection(dbURL, userID, passwd);
log("ScanDataAccessor init: Preparing searchPolicy");
searchPolicy =
dbConnection.prepareStatement("Select * from pinfo where policynumber=?");
log("ScanDataAccessor init: Prepared searchPolicy");
log("ScanDataAccessor init: Preparing searchUnmatchAndPolicy");
tempStr = "Select D.ZOOM100,D.DOCTYPE,D.NEWDOCUMENTCODE,P.PINDEX,P.UINDEX,P.DOCUMENTTYPE,P.PID,";
tempStr = tempStr+"P.IDATE,P.MOVETOINDY,U.USERNAME,P.PAGECOUNT from ";
tempStr = tempStr+"(POLICY P INNER JOIN DOCUMENTTYPE D ON D.DOCNUMBER=P.DOCUMENTTYPE)";
tempStr = tempStr+" FULL JOIN USERINFO U ON U.YUSERN=P.ICODENUM WHERE P.PID=? ";
tempStr = tempStr+"UNION Select D.ZOOM100,D.DOCTYPE,D.NEWDOCUMENTCODE,P.PINDEX,P.UINDEX,P.DOCUMENTTYPE,";
tempStr = tempStr+"P.PID,P.IDATE,P.MOVETOINDY,U.USERNAME,P.PAGECOUNT from (UNMATCH";
tempStr = tempStr+" P INNER JOIN DOCUMENTTYPE D ON D.DOCNUMBER=P.DOCUMENTTYPE) FULL ";
tempStr = tempStr+"JOIN USERINFO U ON U.YUSERN=P.ICODENUM WHERE P.PID=?";
log(tempStr);
searchUnmatchAndPolicy = dbConnection.prepareStatement(tempStr);
log("ScanDataAccessor init: Prepared searchUnmatchAndPolicy");
log("ScanDataAccessor init: Preparing GETIMAGE_WITH_INDEXTYPE");
searchImageInfo =
dbConnection.prepareStatement("Select * from GETIMAGE_WITH_INDEXTYPE(?,?)");
log("ScanDataAccessor init: End");
}
catch (Exception e)
{
cleanUp();
log(e);
}
}
public void destroy()
{
log("policyDataAccessor: destroy");
cleanUp();
}
/**
* Simple method for logging messages to console.
*/
protected void log(Object msg)
{
System.out.println(msg);
}
public void cleanUp()
{
try {
log("Closing database connection");
dbConnection.close();
}
catch (SQLException e)
{
log(e);
}
}

public boolean getImageInformation(int xPid,int xType,HttpServletResponse res)
{
System.out.println("in GetImageInformation getImageInformation");
if (xPid != -1)
{
try
{
log("starting query... image Information");
searchImageInfo.setInt(1,xPid);
searchImageInfo.setInt(2,xType);
ResultSet dataResultSet = searchImageInfo.executeQuery();
log("finishing query... image Information");
byte bx[];
dataResultSet.next();
bx = dataResultSet.getBytes(1);
dataResultSet.close();
res.setContentType("image/tiff");
System.out.println(bx.length);
System.out.println("after while loop");
res.getOutputStream().write(bx);
System.out.println("after res.getoutputstream().write(b)");
res.getOutputStream().flush();
System.out.println("after res.getoutputstream().flush");
res.getOutputStream().close();
System.out.println("after res.getoutputstream().close");
res.flushBuffer();
log("result set closed\n\n");
}
catch (SQLException e)
{
log(e);
}
catch (IOException e)
{
log(e);
}
finally
{
return true;
}
}
else
return false;
}

public Vector getPolicyInformation(String xPolicynumber)
{
System.out.println("in GetPolicyInformation");
int xPid=-1;
xPid=getPid(xPolicynumber);
Vector policyInformationVector = new Vector();
if (xPid != -1)
{
try
{
policyInformation aPolicyInformation = null;
log("starting query... policy Information");
searchUnmatchAndPolicy.setInt(1,xPid);
searchUnmatchAndPolicy.setInt(2,xPid);
ResultSet dataResultSet = searchUnmatchAndPolicy.executeQuery();
log("finishing query... Policy Information");
System.out.println("YYYYYYYYYYYYYYYYYYYYYYYYYYYY");
//********************************************************************************
//------This is where i am calling the ResultSetTOXML class constructor---------//
rstx = new ResultSetToXML(dataResultSet,true);
//********************************************************************************
while (dataResultSet.next())
{
aPolicyInformation = new policyInformation(dataResultSet,xFirstName,xLastName,xMiddleName,xSSN,xPolicyNumber,xCompanyCode,xCoverage,xInsuredNo,xDOB,xApplicationDate);
policyInformationVector.addElement(aPolicyInformation);
}
dataResultSet.close();
log("result set closed\n\n");
}
catch (SQLException e)
{
log(e);
}
finally
{
return policyInformationVector;
}
}
else
return policyInformationVector;
}

public int getPid(String xPolicynumber)
{
int xpid=-1;
try
{
log("starting query... pid");
System.out.println("Policy number "+xPolicynumber);
searchPolicy.setString(1,xPolicynumber);
ResultSet dataResultSet = searchPolicy.executeQuery();
log("finishing query... pid");
dataResultSet.next();
{
xpid= dataResultSet.getInt("PID");
xFirstName=dataResultSet.getString("FIRSTNAME");
xLastName=dataResultSet.getString("LASTNAME");
xMiddleName=dataResultSet.getString("MIDDLENAME");
xSSN=dataResultSet.getString("SSN");
xDOB=dataResultSet.getDate("DOB");
xPolicyNumber=dataResultSet.getString("POLICYNUMBER");
xCompanyCode=dataResultSet.getString("COMPANYCODE");
xCoverage=dataResultSet.getString("COVERAGE");
xInsuredNo=dataResultSet.getString("INSUREDNO");
xApplicationDate=dataResultSet.getDate("APPLICATIONDATE");
}
dataResultSet.close();
System.out.println(xpid);
log("result set closed\n\n");
}
catch (SQLException e)
{
log(e);
return -1;
}
finally
{
return xpid;
}

}
}

//-----------------------------------------------------------------------------//

ResultSetToXML class which creates the XML file from the ResultSet
//-----------------------------------------------------------------------------//
public class ResultSetToXML {
public OutputStream out;
public Element root;
public XMLOutputter outputter;
public Document doc;

public ResultSetToXML(ResultSet rs, boolean checkifnull){
try{
String tagname="";
String tagvalue="";
System.out.println("before the root = new Element()");
//-------------------------------------------------------------//
//----------This is where it stops. I am not getting any erros but its not---------//
//----------doing anything after this code so its not creating XML file.----------//
root = new Element("pinfo");

//-------------------------------------------------------------//
while (rs.next()){
Element users = new Element("Record");
for(int i=1;i<=rs.getMetaData().getColumnCount(); ++i){
tagname= rs.getMetaData().getColumnName(i);
tagvalue=rs.getString(i);
System.out.println(tagname);
System.out.println(tagvalue);
if(checkifnull){
if((tagvalue == null) || (tagvalue.length() < 0) || (tagvalue.equals(""))){
}
else{
users.addContent((new Element(tagname).setText(tagvalue)));
}
}
else{
users.addContent((new Element(tagname).setText(tagvalue)));
}
}
root.addContent(users);
}
out=new FileOutputStream("c:/XMLFile.xml");
doc = new Document(root);
outputter = new XMLOutputter();
outputter.output(doc,out);
}
catch(IOException ioe){
System.out.println(ioe);
}
catch(SQLException sqle){
}
}
}
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I am sorry I have to cross post this
If you are sorry about it you should know not to do it. You obviously read more than one forum, what makes you think the people who might answer your problem don't do the same?
This thread is closed. All replies to the one in XML.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help with XML & ResultSet problem... Urgent Please!!!!!!