Solved

JQgrid JSP integration - data not displayed.

Posted on 2010-09-03
3
3,152 Views
Last Modified: 2012-05-10
II am having problem in displaying data in jqGrid when I am building my XML in JSP. Grid is displayed but without any data.

Here is my JSP which connects to DB and create XML.
==============================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"_http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<% Class.forName("oracle.jdbc.driver.OracleDriver");  %>
<% 
	Connection connection = DriverManager .getConnection( "jdbc:oracle:thin:@localhost:test", "test", "test");
	Statement statement = connection.createStatement() ;
	ResultSet resultset = 
	statement.executeQuery("select * from mytable") ; 
%>
<%
	response.ContentType = "text/xml;charset=utf-8" 
%>
<% out.println("&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;"); %>
<% 
   out.println("&lt;invoices&gt;");
   out.println("&lt;rows&gt;");
   while(resultset.next()){
	 out.println("&lt;row&gt;");
	 out.println("&lt;cell&gt;"+resultset.getString(1)+"&lt;/cell&gt;");
	 out.println("&lt;cell&gt;"+resultset.getString(2)+"&lt;/cell&gt;");
	 out.println("&lt;cell&gt;"+resultset.getString(3)+"&lt;/cell&gt;");
	 out.println("&lt;cell&gt;"+resultset.getString(4)+"&lt;/cell&gt;");
	 out.println("&lt;/row&gt;");
   } 
   out.println("&lt;/rows&gt;"); 
   out.println("&lt;/invoices&gt;");
 %>

Open in new window

]=================================================================================

Here is my other JSP which should display data in JQGrid.

==========================================================
<html>
<head>
<title>jqGrid Demo</title>
<link rel="stylesheet" type="text/css" media="screen" href="themes/basic/grid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="themes/jqModal.css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.js" type="text/javascript"></script>
<script src="js/jqModal.js" type="text/javascript"></script>
<script src="js/jqDnR.js" type="text/javascript"></script>
<script>

<%
response.ContentType = "text/xml;charset=utf-8" 
%>

jQuery(document).ready(function ()
{ jQuery("#list1").jqGrid({ 
    url:'RetrieveData.jsp',
	datatype: "xml",
	 mtype: 'POST',
    colNames:['Inv No','Date', 'Amount','Tax'],
    colModel :[ 
      {name:'invid', index:'invid', width:55, sorttype:'int'}, 
      {name:'invdate', index:'invdate', width:90, sorttype:'date', datefmt:'Y-m-d'}, 
      {name:'amount', index:'amount', width:80, align:'right', sorttype:'float'}, 
      {name:'tax', index:'tax', width:80, align:'right', sorttype:'float'}
     ],
  rowNum:10, 
  autowidth: true, 
  rowList:[10,20,30], 
  pager: jQuery('#pager1'), 
  sortname: 'id', 
  viewrecords: true, 
  sortorder: "desc", 
  caption:"XML Example" 
  }); 
}); 
</script>


</head>
<body> 
<table id="list1" class="scroll"></table> 
<div id="pager1" class="scroll" style="text-align:center;"></div> 
</body> 
</html>

Open in new window

=================================================================================

Above example works if I get the data from static XML file (i.e. - url:'RetrieveData.xml',
). Any suggestion/help would be appreciated.

Thanks
~P


0
Comment
Question by:pramathur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33601430
you've a space before the dot here : DriverManager .getConnection
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33601534
The following RetrieveData.jsp work for me :

(the JSP displaying the data in JQGrid is fine)
<%@ page contentType="text/xml" %>
<%@ page import="java.sql.*" %>
<% Class.forName("oracle.jdbc.driver.OracleDriver"); %>
<% 
	Connection connection = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:test", "test", "test");	
	Statement statement = connection.createStatement();
	ResultSet resultset = statement.executeQuery("select * from test"); 
%>

<invoice>
<rows>
<% 
   while(resultset.next()) {
	 out.println("<row>");
	 out.println("<cell>" +resultset.getString(1) + "</cell>");
	 out.println("<cell>" +resultset.getString(2) + "</cell>");
	 out.println("<cell>" +resultset.getString(3) + "</cell>");
	 out.println("<cell>" +resultset.getString(4) + "</cell>");
	 out.println("</row>");
   } 
%>
</rows>
</invoice>

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33907133
Thanks for the points!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Determining the an SCCM package name from the Package ID
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question