Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: probs with jsp......
PostPosted: Mon Mar 28, 2005 2:45 pm 


This is the question
------------------
Driver, URL, and query Strings for JDBC: "com.mysql.jdbc.Driver", "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF8", “select * from testableâ€￾

And the columns-types of this table are: int, text, text, text, int, date, int

As for the currency fields, they are saved as Kuwaiti-fils integers, so String-Formatting is required.



And the html output template looks like the following:



<table id="mat" width="95%" border="1">

<th width="3%" class="styleFieldLabel">Serial No.</TH>

<th width="48%" class="styleFieldLabel">Material Description</th>

<th width="12%" class="styleFieldLabel">Company Name</th>

<th width="10%" class="styleFieldLabel">Invoice No.</th>

<th width="4%" class="styleFieldLabel">Quantity.</th>

<th width="7%" class="styleFieldLabel">Date.</th>

<th width="6%" class="styleFieldLabel">Price/ea</th>

<th width="10%" class="styleFieldLabel">Total Price</th>

<!—and then JSP code for the following: à

<tr>

<td> <!—expected JSP code à </td>

.

.

.

<td> <!—expected JSP code à </td>

</tr>

.

.

.



</table>

Please take into consideration the case of empty set ResultSet, please tell me how you will handle it according to your experience,which is a single jsp file

--------------------------------------------
i gave the solution for this is



<table id="mat" width="95%" border="1">

<th width="3%" class="styleFieldLabel">Serial No.</TH>

<th width="48%" class="styleFieldLabel">Material Description</th>

<th width="12%" class="styleFieldLabel">Company Name</th>

<th width="10%" class="styleFieldLabel">Invoice No.</th>

<th width="4%" class="styleFieldLabel">Quantity.</th>
<th width="7%" class="styleFieldLabel">Date.</th>

<th width="6%" class="styleFieldLabel">Price/ea</th>

<th width="10%" class="styleFieldLabel">Total Price</th>

<%@ page import="java.sql.*" %>
<%
DecimalFormat num=new DecimalFormat("0.000");


here this looks nothing like JDBC
//create the cursor
testcursor=com.cursor("select * from testable");
//check validity of cursor
if(testcursor && com.majorErrorcode()==0)
{
while(testcursor.next())
{ again, this looks nothing like JSP.
write("<tr><td>"+testcursor.serialno+"</td>
+"<td>"+testcursor.MDesc+"</td>"+"td>"+testcursor.CompName+"</td>"
+"<td>"+testcursor.InvNo+"</td>"+"<td>"+testcursor.Qty+"</td>"+"<td>"
+testcursor.date+"</td>"+"<td>"+testcursor.price+"</td>"+"<td>"
+testcursor.price*testcursor.qty+"</td></tr>";

}

testcursor.close();
}
%>

</Table>
-------------------------------------
another solution is

<%
try
{
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select * from testable");
while (resultSet.next())
{ %>
<tr>
<td><%= resultSet.getString(serialno) %></td>
<td><%= resultSet.getString(mdesc) %></td>
<td><%= resultSet.getString(compname) %></td>
<td><%= resultSet.getString(invno) %></td>
<td><%= resultSet.getInt(qty) %></td>
<td><%= resultSet.getDate(date) %></td>
<td><%= resultSet.getInt(qty)* resultSet.getInt(price) %></td>
<% }
catch(SQLException e)
{
System.out.println("Couldn't connect to the database");
}
finally
{
if (connection!=null) connection.close();
if (statement!=null) statement.close();
if (resultset!=null) resultset.close();
}
%>


-------------------------------
i want to know is this correct or not
if wrong pls send correct code,it wil be a great help

expecting reply


Top
  
 
 Post subject: Need More Details
PostPosted: Tue Mar 29, 2005 7:05 am 
Offline

Joined: Sun Mar 20, 2005 6:26 pm
Posts: 29

Hi,
If you just want to know the correctness.Seems to be correct.If you have error, please paste it here.

If you have any other question . let me know


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group