Solved

JQgrid JSP integration - data not displayed.

Posted on 2010-09-03
3
3,141 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

How do we balance the user experience (UX) with reasonable security measures? It can be done, if you keep these fundamentals in mind.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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