my dog learned polymorphism*
The moose likes JSP and the fly likes xml from jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "xml from jsp" Watch "xml from jsp" New topic
Author

xml from jsp

vartika vaish
Greenhorn

Joined: Apr 15, 2008
Posts: 15
hi,

We are trying to generate an xml file using jsp. the code written is attached below. this si what we have been doing is in MyEclipse.

When we run this it gives us unable to load xml xml format invalid.

kindly look at the code and see what changes need to take.

this is being used for dhtmlxGrid dynamic rendering.

please help..

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ page import = "java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

</head>

<body>

<%

//String db_ipp_addr = "localhost";
//String db_username = "root";
//String db_password = "1";
//String db_name = "sampleDB";

// set content type and xml tag

response.setContentType("text/xml");
out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

// define variables from incoming values
String posStart = "";
if (request.getParameter("posStart") != null){
posStart = request.getParameter("posStart");
}else{
posStart = "0";
}

String count = "";
if (request.getParameter("count") != null){
count = request.getParameter("count");
}else{
count = "100";
}

// connect to database
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
//String connectionURL = "jdbc:mysql://" + db_ipp_addr + ":3306/" + db_name;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


//com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbcdbc:data");


//, db_username, db_password);

// query to products table
String sql = "SELECT * FROM Employee";

// if this is the first query - get total number of records in the query result
String totalCount = "";
if (posStart.equals("0")){
String sqlCount = "Select count(*) as cnt from Employee";
statement = connection.createStatement();
rs = statement.executeQuery(sqlCount);
rs.next();
totalCount = rs.getString("cnt");

rs.close();
} else {
totalCount = "";
}

// add limits to query to get only rows necessary for output
// sql += " LIMIT " + posStart + "," + count;

// Execute the query
statement = connection.createStatement();
rs = statement.executeQuery(sql);

// output data in XML format
out.println("<rows total_count='" + totalCount + "' pos='" + posStart + "'>");
int id = 0;
while (rs.next()) {
String Str_id = id + " ";

out.println("<row id=\"" + Str_id + "\">");
out.println("<cell>");
out.println(rs.getString("empId")); // value for product name
out.println("</cell>");
out.println("<cell>");
out.println(rs.getString("empName")); // value for internal code
out.println("</cell>");
out.println("<cell>");
out.println(rs.getString("empPass")); // value for price
out.println("</cell>");
out.println("</row>");
id++;
}
out.write("</rows>");
rs.close();
%>
</body>
</html>


please help
 
Consider Paul's rocket mass heater.
 
subject: xml from jsp
 
Similar Threads
how to upload and retrive a image from mysql database
How to retrive data two times from database in sinble jsp page.
Pretty Basic but help needed
JSP-Tomcat-MySQL connection problems
Exception! Column not found!?