• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Issue Req Storing Result Set Data in a XML File  RSS feed

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am developing a project using jsp & servlet.
i want�create a xml from result set using document builder but when the servlet is executed it displays the Http Status 500 error

tell me what to do . where to place that xml file

is there other for writing result set data as xml
below is the code that� does not work

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Document mapDoc;
Document dataDoc=null;
String XmlFileName=request.getParameter("filename");
DocumentBuilder db;
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
System.out.println(XmlFileName);
try {
db=dbf.newDocumentBuilder();
mapDoc=db.parse(XmlFileName);
dataDoc=db.newDocument();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
System.out.println("sax");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("IO ->");
e.printStackTrace();
}
Connection con;
Statement st;
ResultSet rs;
ResultSetMetaData rsd=null;
Element DocRoot=null;
String query="select * from StationarRequest";
try {
Class.forName(DbConnect.getDriverName());
con=DriverManager.getConnection(DbConnect.getDsnName(),DbConnect.getUid(),DbConnect.getPwd());
st=con.createStatement();
rs=st.executeQuery(query);
rsd=rs.getMetaData();
DocRoot=dataDoc.createElement("StationaryDb");
while(rs.next())
{
Element row=dataDoc.createElement("Stationary");
for(int i=0;i<rsd.getColumnCount();i++)
{
String colName=rsd.getColumnName(i);
String colType=rsd.getColumnTypeName(i);
System.out.println(colType);
String colValue="";
if(colType.equals("String"))
{
colValue=rs.getString(i);
}
else if(colType.equals("int"))
{
colValue=rs.getInt(i)+"";
}
else if(colType.equals("float"))
{
colValue=rs.getFloat(i)+"";
}
else if(colType.equals("double"))
{
colValue=rs.getDouble(i)+"";
}
Element DataCol=dataDoc.createElement(colName);
DataCol.appendChild(dataDoc.createTextNode(colValue));
row.appendChild(DataCol);
}
DocRoot.appendChild(row);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("class");
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("sql");
e.printStackTrace();
}
dataDoc.appendChild(DocRoot);
System.out.println("The Result Set is written into XML File");
}
 
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K Sathya Narayanan,
Javaranch tip:
If you use UBB CODE tags] when posting your code, the indentation will be preserved. It will also use a mono spaced font.
Doing this will increase the chances that someone will read it enough to spot the problem.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see creation of a DOM in memory but I don't see where that DOM is used to create either a file on the server or as output to the response.

Status 500 just says something went wrong. Are you getting the System.out.print messages where you can see them? Right now we have no information as to what went wrong.

The usage db.parse(XmlFileName) probably is throwing an IOException because it can't find the file. Code that depends on the "current" directory simply does not work in a servlet.

Surely you can get those stack traces logged better.

Bill
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!