Solved

JQgrid JSP integration - data not displayed.

Posted on 2010-09-03
3
3,130 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
  • 3
3 Comments
 
LVL 82

Accepted Solution

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

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
Thanks for the points!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
A procedure for exporting installed hotfix details of remote computers using powershell
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now