Forum
November 2nd, 2014
A
A
A
The forums are currently locked and only available for read only access
Topic RSS
Jqgrid with Servlet and MySql not working
01/07/2014
13:04
13:04
legalizeSINCE88
New Member
Members
Forum Posts: 2
Member Since:
01/07/2014
01/07/2014
Offline
Hello,
Â
i have the following code:
Â
<span class="kwd">package</span><span class="pln"> server</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">IOException</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">PrintWriter</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">Connection</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">DriverManager</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">PreparedStatement</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">ResultSet</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">ResultSetMetaData</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="typ">ServletException</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="pln">annotation</span><span class="pun">.</span><span class="typ">WebServlet</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="pln">http</span><span class="pun">.</span><span class="typ">HttpServlet</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="pln">http</span><span class="pun">.</span><span class="typ">HttpServletRequest</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="pln">http</span><span class="pun">.</span><span class="typ">HttpServletResponse</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> net</span><span class="pun">.</span><span class="pln">sf</span><span class="pun">.</span><span class="pln">json</span><span class="pun">.</span><span class="typ">JSONArray</span><span class="pun">;</span><span class="kwd">import</span><span class="pln"> net</span><span class="pun">.</span><span class="pln">sf</span><span class="pun">.</span><span class="pln">json</span><span class="pun">.</span><span class="typ">JSONObject</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">json</span><span class="pun">.</span><span class="pln">simple</span><span class="pun">.</span><span class="typ">JSONValue</span><span class="pun">;<br /><br /></span><span class="lit">@WebServlet</span><span class="pun">(</span><span class="str">"/servlet"</span><span class="pun">)</span><span class="kwd">public</span><span class="kwd">class</span><span class="pln"> servlet </span><span class="kwd">extends</span><span class="typ">HttpServlet</span><span class="pun">{</span><span class="kwd">private</span><span class="kwd">static</span><span class="kwd">final</span><span class="kwd">long</span><span class="pln"> serialVersionUID </span><span class="pun">=</span><span class="lit">1L</span><span class="pun">;</span><span class="kwd">public</span><span class="pln"> servlet</span><span class="pun">()</span><span class="pun">{</span><span class="kwd">super</span><span class="pun">();</span><span class="pun">}</span><span class="kwd">protected</span><span class="kwd">void</span><span class="pln"> doPost</span><span class="pun">(</span><span class="typ">HttpServletRequest</span><span class="pln"> request</span><span class="pun">,</span><span class="typ">HttpServletResponse</span><span class="pln"> response</span><span class="pun">)</span><span class="kwd">throws</span><span class="typ">ServletException</span><span class="pun">,</span><span class="typ">IOException</span><span class="pun">{</span><span class="pln"> doGet</span><span class="pun">(</span><span class="pln">request</span><span class="pun">,</span><span class="pln"> response</span><span class="pun">);</span><span class="pun">}</span><span class="kwd">protected</span><span class="kwd">void</span><span class="pln"> doGet</span><span class="pun">(</span><span class="typ">HttpServletRequest</span><span class="pln"> request</span><span class="pun">,</span><span class="typ">HttpServletResponse</span><span class="pln"> response</span><span class="pun">)</span><span class="kwd">throws</span><span class="typ">ServletException</span><span class="pun">,</span><span class="typ">IOException</span><span class="pun">{</span><span class="pln"> response</span><span class="pun">.</span><span class="pln">setContentType</span><span class="pun">(</span><span class="str">"application/json"</span><span class="pun">);<br /></span><span class="typ">PrintWriter</span><span class="kwd">out</span><span class="pun">=</span><span class="pln"> response</span><span class="pun">.</span><span class="pln">getWriter</span><span class="pun">();<br /></span><span class="typ">JSONObject</span><span class="pln"> responseData</span><span class="pun">=</span><span class="kwd">new</span><span class="typ">JSONObject</span><span class="pun">();<br /></span><span class="typ">JSONArray</span><span class="pln"> jArray</span><span class="pun">=</span><span class="kwd">new</span><span class="typ">JSONArray</span><span class="pun">();<br /></span><span class="kwd">try</span><span class="pun">{<br /></span><span class="typ">Class</span><span class="pun">.</span><span class="pln">forName</span><span class="pun">(</span><span class="str">"com.mysql.jdbc.Driver"</span><span class="pun">);<br /></span><span class="typ">Connection</span><span class="pln"> con </span><span class="pun">=</span><span class="typ">DriverManager</span><span class="pun">.</span><span class="pln">getConnection</span><span class="pun">(</span><span class="str">"jdbc:mysql://localhost:8080/neue"</span><span class="pun">,</span><span class="str">"*****"</span><span class="pun">,</span><span class="str">"****"</span><span class="pun">);<br /></span><span class="typ">PreparedStatement</span><span class="pln"> prepared </span><span class="pun">=</span><span class="pln"> con</span><span class="pun">.</span><span class="pln">prepareStatement</span><span class="pun">(</span><span class="str">"Select * from person"</span><span class="pun">);<br /></span><span class="typ">ResultSet</span><span class="pln"> rs </span><span class="pun">=</span><span class="pln"> prepared</span><span class="pun">.</span><span class="pln">executeQuery</span><span class="pun">();<br /></span><span class="typ">ResultSetMetaData</span><span class="pln"> rsmd </span><span class="pun">=</span><span class="pln"> rs</span><span class="pun">.</span><span class="pln">getMetaData</span><span class="pun">();<br /></span><span class="kwd">int</span><span class="pln"> numberOfColumns </span><span class="pun">=</span><span class="pln"> rsmd</span><span class="pun">.</span><span class="pln">getColumnCount</span><span class="pun">();<br /></span><span class="kwd">while</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="kwd">next</span><span class="pun">())</span><span class="pun">{<br /></span><span class="typ"> JSONObject</span><span class="pln"> jObject</span><span class="pun">=</span><span class="kwd">new</span><span class="typ">JSONObject</span><span class="pun">();<br /></span><span class="typ"> JSONArray</span><span class="typ">Jarr</span><span class="pun">=</span><span class="kwd">new</span><span class="typ">JSONArray</span><span class="pun">();<br /></span><span class="typ"> Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"a"</span><span class="pun">));<br /></span><span class="typ"> Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"b"</span><span class="pun">));<br /> </span><span class="typ">Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"c"</span><span class="pun">));<br /> </span><span class="typ">Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"d"</span><span class="pun">));<br /> </span><span class="typ">Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"e"</span><span class="pun">));<br /></span><span class="pln"> jObject</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"cell"</span><span class="pun">,</span><span class="typ">Jarr</span><span class="pun">);</span><span class="pln"> jArray</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">jObject</span><span class="pun">);<br /></span><span class="pun">}<br /></span><span class="pln"> responseData</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"total"</span><span class="pun">,</span><span class="lit">5</span><span class="pun">);</span><span class="pln"> responseData</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"page"</span><span class="pun">,</span><span class="lit">1</span><span class="pun">);</span><span class="pln"> responseData</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"records"</span><span class="pun">,</span><span class="pln">numberOfColumns</span><span class="pun">);</span><span class="pln"> responseData</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"rows"</span><span class="pun">,</span><span class="pln">jArray</span><span class="pun">);</span><span class="kwd">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="typ">JSONValue</span><span class="pun">.</span><span class="pln">toJSONString</span><span class="pun">(</span><span class="pln">responseData</span><span class="pun">));<br /></span><span class="pun">}</span><span class="kwd">catch</span><span class="pun">(</span><span class="typ">Exception</span><span class="pln"> e</span><span class="pun">)</span><span class="pun">{</span><span class="pun">}<br /></span><span class="pun">}<br /><br />And my script.js file looks like this:<br /><br /><br /><br /></span>
<span class="pln">$</span><span class="pun">(</span><span class="pln">document</span><span class="pun">).</span><span class="pln">ready</span><span class="pun">(</span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"> $</span><span class="pun">(</span><span class="str">"#list"</span><span class="pun">).</span><span class="pln">jqGrid</span><span class="pun">({</span><span class="pln"> url</span><span class="pun">:</span><span class="str">'servlet'</span><span class="pun">,</span><span class="pln"> datatype</span><span class="pun">:</span><span class="str">"json"</span><span class="pun">,</span><span class="pln"> mtype </span><span class="pun">:</span><span class="str">'get'</span><span class="pun">,</span><span class="pln"> colNames</span><span class="pun">:[</span><span class="str">'a'</span><span class="pun">,</span><span class="str">'b'</span><span class="pun">,</span><span class="str">'c'</span><span class="pun">,</span><span class="str">'d'</span><span class="pun">,</span><span class="str">'e'</span><span class="pun">],</span><span class="pln"> colModel</span><span class="pun">:[</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'a'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'a'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">75</span><span class="pun">},</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'b'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'b'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">90</span><span class="pun">},</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'c'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'c'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">100</span><span class="pun">},</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'d'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'d'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">80</span><span class="pun">,</span><span class="pln">align</span><span class="pun">:</span><span class="str">"right"</span><span class="pun">},</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'e'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'e'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">80</span><span class="pun">,</span><span class="pln"> align</span><span class="pun">:</span><span class="str">"right"</span><span class="pun">},</span><span class="pun">],</span><span class="pln"> rowNum</span><span class="pun">:</span><span class="lit">10</span><span class="pun">,</span><span class="pln"> autowidth</span><span class="pun">:</span><span class="kwd">true</span><span class="pun">,</span><span class="pln"> rowList</span><span class="pun">:[</span><span class="lit">10</span><span class="pun">,</span><span class="lit">20</span><span class="pun">,</span><span class="lit">30</span><span class="pun">],</span><span class="pln"> pager</span><span class="pun">:</span><span class="pln"> jQuery</span><span class="pun">(</span><span class="str">'#pager'</span><span class="pun">),</span><span class="pln"> sortname</span><span class="pun">:</span><span class="str">'id'</span><span class="pun">,</span><span class="pln"> viewrecords</span><span class="pun">:</span><span class="kwd">true</span><span class="pun">,</span><span class="pln"> sortorder</span><span class="pun">:</span><span class="str">"desc"</span><span class="pun">,</span><span class="pln"> caption</span><span class="pun">:</span><span class="str">"JSON Example"</span><span class="pun">,</span><span class="pln"> jsonReader</span><span class="pun">:</span><span class="pun">{</span><span class="pln"> repeatitems</span><span class="pun">:</span><span class="kwd">false</span><span class="pun">,</span><span class="pln"> id</span><span class="pun">:</span><span class="str">"0"</span><span class="pun">,</span><span class="pln"> cell</span><span class="pun">:</span><span class="str">""</span><span class="pun">,</span><span class="pln"> root</span><span class="pun">:</span><span class="str">"rows"</span><span class="pun">,</span><span class="pln"> page</span><span class="pun">:</span><span class="kwd">function</span><span class="pun">()</span><span class="pun">{</span><span class="kwd">return</span><span class="lit">1</span><span class="pun">;</span><span class="pun">},</span><span class="pln"> total</span><span class="pun">:</span><span class="kwd">function</span><span class="pun">()</span><span class="pun">{</span><span class="kwd">return</span><span class="lit">1</span><span class="pun">;</span><span class="pun">},</span><span class="pln"> records</span><span class="pun">:</span><span class="kwd">function</span><span class="pun">(</span><span class="pln">obj</span><span class="pun">)</span><span class="pun">{</span><span class="kwd">return</span><span class="pln"> obj</span><span class="pun">.</span><span class="pln">length</span><span class="pun">;</span><span class="pun">}</span><span class="pun">}</span><span class="pun">}).</span><span class="pln">navGrid</span><span class="pun">(</span><span class="str">'#pager'</span><span class="pun">,{</span><span class="pln">edit</span><span class="pun">:</span><span class="kwd">false</span><span class="pun">,</span><span class="pln">add</span><span class="pun">:</span><span class="kwd">false</span><span class="pun">,</span><span class="kwd">del</span><span class="pun">:</span><span class="kwd">false</span><span class="pun">});</span>
<span class="pun">}<br /><br />But my table is empty. Nothing happens.<br /><br />The only thing i get from the server is this message(Firebug):<br /><br /><strong>Status-Code: 500 Internal Server Error</strong><br /><br /><br />I´ve tried to set a breakpoint in my code and run in debug-mode but it also not work.<br /><br />Can somewone please help me<br /><br />Many thanks<br /><br /><br /></span>
01/07/2014
13:05
13:05
legalizeSINCE88
New Member
Members
Forum Posts: 2
Member Since:
01/07/2014
01/07/2014
Offline
legalizeSINCE88 said
Hello,Â
i have the following code:
Â
<span class="kwd">"package</span><span class="pln"> server</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">IOException</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.</span><span class="typ">PrintWriter</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">Connection</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">DriverManager</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">PreparedStatement</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">ResultSet</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="typ">ResultSetMetaData</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="typ">ServletException</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="pln">annotation</span><span class="pun">.</span><span class="typ">WebServlet</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="pln">http</span><span class="pun">.</span><span class="typ">HttpServlet</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="pln">http</span><span class="pun">.</span><span class="typ">HttpServletRequest</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> javax</span><span class="pun">.</span><span class="pln">servlet</span><span class="pun">.</span><span class="pln">http</span><span class="pun">.</span><span class="typ">HttpServletResponse</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> net</span><span class="pun">.</span><span class="pln">sf</span><span class="pun">.</span><span class="pln">json</span><span class="pun">.</span><span class="typ">JSONArray</span><span class="pun">;</span><span class="kwd">import</span><span class="pln"> net</span><span class="pun">.</span><span class="pln">sf</span><span class="pun">.</span><span class="pln">json</span><span class="pun">.</span><span class="typ">JSONObject</span><span class="pun">;<br /></span><span class="kwd">import</span><span class="pln"> org</span><span class="pun">.</span><span class="pln">json</span><span class="pun">.</span><span class="pln">simple</span><span class="pun">.</span><span class="typ">JSONValue</span><span class="pun">;<br /><br /></span><span class="lit">@WebServlet</span><span class="pun">(</span><span class="str">"/servlet"</span><span class="pun">)</span><span class="kwd">public</span><span class="kwd">class</span><span class="pln"> servlet </span><span class="kwd">extends</span><span class="typ">HttpServlet</span><span class="pun">{</span><span class="kwd">private</span><span class="kwd">static</span><span class="kwd">final</span><span class="kwd">long</span><span class="pln"> serialVersionUID </span><span class="pun">=</span><span class="lit">1L</span><span class="pun">;</span><span class="kwd">public</span><span class="pln"> servlet</span><span class="pun">()</span><span class="pun">{</span><span class="kwd">super</span><span class="pun">();</span><span class="pun">}</span><span class="kwd">protected</span><span class="kwd">void</span><span class="pln"> doPost</span><span class="pun">(</span><span class="typ">HttpServletRequest</span><span class="pln"> request</span><span class="pun">,</span><span class="typ">HttpServletResponse</span><span class="pln"> response</span><span class="pun">)</span><span class="kwd">throws</span><span class="typ">ServletException</span><span class="pun">,</span><span class="typ">IOException</span><span class="pun">{</span><span class="pln"><br /> doGet</span><span class="pun">(</span><span class="pln">request</span><span class="pun">,</span><span class="pln"> response</span><span class="pun">);</span><span class="pun">}</span><span class="kwd">protected</span><span class="kwd">void</span><span class="pln"> doGet</span><span class="pun">(</span><span class="typ">HttpServletRequest</span><span class="pln"> request</span><span class="pun">,</span><span class="typ">HttpServletResponse</span><span class="pln"> response</span><span class="pun">)</span><span class="kwd">throws</span><span class="typ">ServletException</span><span class="pun">,</span><span class="typ">IOException</span><span class="pun">{</span><span class="pln"><br /> <br /> response</span><span class="pun">.</span><span class="pln">setContentType</span><span class="pun">(</span><span class="str">"application/json"</span><span class="pun">);<br /></span><span class="typ">PrintWriter</span><span class="kwd">out</span><span class="pun">=</span><span class="pln"> response</span><span class="pun">.</span><span class="pln">getWriter</span><span class="pun">();<br /></span><span class="typ">JSONObject</span><span class="pln"> responseData</span><span class="pun">=</span><span class="kwd">new</span><span class="typ">JSONObject</span><span class="pun">();<br /></span><span class="typ">JSONArray</span><span class="pln"> jArray</span><span class="pun">=</span><span class="kwd">new</span><span class="typ">JSONArray</span><span class="pun">();<br /></span><span class="kwd">try</span><span class="pun">{<br /></span><span class="typ">Class</span><span class="pun">.</span><span class="pln">forName</span><span class="pun">(</span><span class="str">"com.mysql.jdbc.Driver"</span><span class="pun">);<br /></span><span class="typ">Connection</span><span class="pln"> con </span><span class="pun">=</span><span class="typ">DriverManager</span><span class="pun">.</span><span class="pln">getConnection</span><span class="pun">(</span><span class="str">"jdbc:mysql://localhost:8080/neue"</span><span class="pun">,</span><span class="str">"*****"</span><span class="pun">,</span><span class="str">"****"</span><span class="pun">);<br /></span><span class="typ">PreparedStatement</span><span class="pln"> prepared </span><span class="pun">=</span><span class="pln"> con</span><span class="pun">.</span><span class="pln">prepareStatement</span><span class="pun">(</span><span class="str">"Select * from person"</span><span class="pun">);<br /></span><span class="typ">ResultSet</span><span class="pln"> rs </span><span class="pun">=</span><span class="pln"> prepared</span><span class="pun">.</span><span class="pln">executeQuery</span><span class="pun">();<br /></span><span class="typ">ResultSetMetaData</span><span class="pln"> rsmd </span><span class="pun">=</span><span class="pln"> rs</span><span class="pun">.</span><span class="pln">getMetaData</span><span class="pun">();<br /></span><span class="kwd">int</span><span class="pln"> numberOfColumns </span><span class="pun">=</span><span class="pln"> rsmd</span><span class="pun">.</span><span class="pln">getColumnCount</span><span class="pun">();<br /></span><span class="kwd">while</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="kwd">next</span><span class="pun">())</span><span class="pun">{<br /></span><span class="typ"> JSONObject</span><span class="pln"> jObject</span><span class="pun">=</span><span class="kwd">new</span><span class="typ">JSONObject</span><span class="pun">();<br /></span><span class="typ"> JSONArray</span><span class="typ">Jarr</span><span class="pun">=</span><span class="kwd">new</span><span class="typ">JSONArray</span><span class="pun">();<br /></span><span class="typ"> Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"a"</span><span class="pun">));<br /></span><span class="typ"> Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"b"</span><span class="pun">));<br /> </span><span class="typ">Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"c"</span><span class="pun">));<br /> </span><span class="typ">Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"d"</span><span class="pun">));<br /> </span><span class="typ">Jarr</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">rs</span><span class="pun">.</span><span class="pln">getString</span><span class="pun">(</span><span class="str">"e"</span><span class="pun">));<br /></span><span class="pln"><br /> jObject</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"cell"</span><span class="pun">,</span><span class="typ">Jarr</span><span class="pun">);</span><span class="pln"><br /> jArray</span><span class="pun">.</span><span class="pln">add</span><span class="pun">(</span><span class="pln">jObject</span><span class="pun">);<br /></span><span class="pun">}<br /></span><span class="pln"><br /> responseData</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"total"</span><span class="pun">,</span><span class="lit">5</span><span class="pun">);</span><span class="pln"><br /> responseData</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"page"</span><span class="pun">,</span><span class="lit">1</span><span class="pun">);</span><span class="pln"><br /> responseData</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"records"</span><span class="pun">,</span><span class="pln">numberOfColumns</span><span class="pun">);</span><span class="pln"><br /> <br /> responseData</span><span class="pun">.</span><span class="pln">put</span><span class="pun">(</span><span class="str">"rows"</span><span class="pun">,</span><span class="pln">jArray</span><span class="pun">);</span><span class="kwd">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="typ">JSONValue</span><span class="pun">.</span><span class="pln">toJSONString</span><span class="pun">(</span><span class="pln">responseData</span><span class="pun">));<br /></span><span class="pun">}</span><span class="kwd">catch</span><span class="pun">(</span><span class="typ">Exception</span><span class="pln"> e</span><span class="pun">)</span><span class="pun">{</span><span class="pun">}<br /></span><span class="pun">}<br />"<br /><br />And my script.js file looks like this:<br /><br /><br /><br /></span><span class="pln">"$</span><span class="pun">(</span><span class="pln">document</span><span class="pun">).</span><span class="pln">ready</span><span class="pun">(</span><span class="kwd">function</span><span class="pun">(){</span><span class="pln"><br /> $</span><span class="pun">(</span><span class="str">"#list"</span><span class="pun">).</span><span class="pln">jqGrid</span><span class="pun">({</span><span class="pln"><br /> url</span><span class="pun">:</span><span class="str">'servlet'</span><span class="pun">,</span><span class="pln"><br /> datatype</span><span class="pun">:</span><span class="str">"json"</span><span class="pun">,</span><span class="pln"><br /> mtype </span><span class="pun">:</span><span class="str">'get'</span><span class="pun">,</span><span class="pln"><br /> colNames</span><span class="pun">:[</span><span class="str">'a'</span><span class="pun">,</span><span class="str">'b'</span><span class="pun">,</span><span class="str">'c'</span><span class="pun">,</span><span class="str">'d'</span><span class="pun">,</span><span class="str">'e'</span><span class="pun">],</span><span class="pln"><br /> colModel</span><span class="pun">:[</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'a'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'a'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">75</span><span class="pun">},</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'b'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'b'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">90</span><span class="pun">},</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'c'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'c'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">100</span><span class="pun">},</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'d'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'d'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">80</span><span class="pun">,</span><span class="pln">align</span><span class="pun">:</span><span class="str">"right"</span><span class="pun">},</span><span class="pun">{</span><span class="pln">name</span><span class="pun">:</span><span class="str">'e'</span><span class="pun">,</span><span class="pln">index</span><span class="pun">:</span><span class="str">'e'</span><span class="pun">,</span><span class="pln"> width</span><span class="pun">:</span><span class="lit">80</span><span class="pun">,</span><span class="pln"> align</span><span class="pun">:</span><span class="str">"right"</span><span class="pun">},</span><span class="pun">],</span><span class="pln"><br /> <br /> rowNum</span><span class="pun">:</span><span class="lit">10</span><span class="pun">,</span><span class="pln"><br /> autowidth</span><span class="pun">:</span><span class="kwd">true</span><span class="pun">,</span><span class="pln"><br /> rowList</span><span class="pun">:[</span><span class="lit">10</span><span class="pun">,</span><span class="lit">20</span><span class="pun">,</span><span class="lit">30</span><span class="pun">],</span><span class="pln"><br /> pager</span><span class="pun">:</span><span class="pln"> jQuery</span><span class="pun">(</span><span class="str">'#pager'</span><span class="pun">),</span><span class="pln"><br /> sortname</span><span class="pun">:</span><span class="str">'id'</span><span class="pun">,</span><span class="pln"><br /> viewrecords</span><span class="pun">:</span><span class="kwd">true</span><span class="pun">,</span><span class="pln"><br /> sortorder</span><span class="pun">:</span><span class="str">"desc"</span><span class="pun">,</span><span class="pln"><br /> caption</span><span class="pun">:</span><span class="str">"JSON Example"</span><span class="pun">,</span><span class="pln"><br /> jsonReader</span><span class="pun">:</span><span class="pun">{</span><span class="pln"><br /> repeatitems</span><span class="pun">:</span><span class="kwd">false</span><span class="pun">,</span><span class="pln"><br /> id</span><span class="pun">:</span><span class="str">"0"</span><span class="pun">,</span><span class="pln"><br /> cell</span><span class="pun">:</span><span class="str">""</span><span class="pun">,</span><span class="pln"><br /> root</span><span class="pun">:</span><span class="str">"rows"</span><span class="pun">,</span><span class="pln"><br /> page</span><span class="pun">:</span><span class="kwd">function</span><span class="pun">()</span><span class="pun">{</span><span class="kwd">return</span><span class="lit">1</span><span class="pun">;</span><span class="pun">},</span><span class="pln"><br /> total</span><span class="pun">:</span><span class="kwd">function</span><span class="pun">()</span><span class="pun">{</span><span class="kwd">return</span><span class="lit">1</span><span class="pun">;</span><span class="pun">},</span><span class="pln"><br /> records</span><span class="pun">:</span><span class="kwd">function</span><span class="pun">(</span><span class="pln">obj</span><span class="pun">)</span><span class="pun">{</span><span class="kwd">return</span><span class="pln"> obj</span><span class="pun">.</span><span class="pln">length</span><span class="pun">;</span><span class="pun">}</span><span class="pun">}</span><span class="pun">}).</span><span class="pln">navGrid</span><span class="pun">(</span><span class="str">'#pager'</span><span class="pun">,{</span><span class="pln">edit</span><span class="pun">:</span><span class="kwd">false</span><span class="pun">,</span><span class="pln">add</span><span class="pun">:</span><span class="kwd">false</span><span class="pun">,</span><span class="kwd">del</span><span class="pun">:</span><span class="kwd">false</span><span class="pun">});</span><span class="pun">}<br />"<br />But my table is empty. Nothing happens.<br /><br />The only thing i get from the server is this message(Firebug):<br /><br /><strong>Status-Code: 500 Internal Server Error</strong><br /><br /><br />I´ve tried to set a breakpoint in my code and run in debug-mode but it also not work.<br /><br />Can somewone please help me<br /><br />Many thanks<br /><br /><br /></span>
Forum Timezone: Europe/Sofia
Most Users Ever Online: 715
Currently Online:
39 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66