Comment on Tutorial - JSP Example to connect to MS SQL database and retrieve records By Abinaya



Comment Added by : Harshal

Comment Added at : 2013-02-19 14:56:35

Comment on Tutorial : JSP Example to connect to MS SQL database and retrieve records By Abinaya
I am getting a blank page. Closed the table tag and added the headers. Below is the modified code. Please let me know what is the issue with this?

<html>
<head><title>Enter to database</title></head>
<body>
<table border="5">
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>
<%

java.sql.Connection con;
java.sql.Statement s;
java.sql.ResultSet rs;
java.sql.PreparedStatement pst;

con=null;
s=null;
pst=null;
rs=null;

// Remember to change the next line with your own environment
String url=
"jdbc:jtds:sqlserver://harshal:1433/jasptest";
String id= "sa";
String pass= "password";
try{

Class.forName("net.sourceforge.jtds.jdbc.Driver");
con = java.sql.DriverManager.getConnection(url, id, pass);

}catch(ClassNotFoundException cnfex){
cnfex.printStackTrace();

}
//String sql = "select * from tbl_sys_user";
String sql = "select top 10 * from tbl_sys_user";
try{
s = con.createStatement();
rs = s.executeQuery(sql);
%>

<%
while( rs.next() ){
%>


<tr>
<th>Header 1
<td><%= rs.getString("cust_id") %></td>
</th>
</tr>

<tr>
<th> Header 2
<td><%= rs.getString("rdate") %></td>
<th>
</tr>

<tr>
<th>
<td><%= rs.getString("email") %></td>
</th>
</tr>
<%
}
%>

<%

}
catch(Exception e){e.printStackTrace();}
finally{
if(rs!=null) rs.close();
if(s!=null) s.close();
if(con!=null) con.close();
}

%>
</table>
</body>
</html>


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. aoa i am for the first time learning programing pl
View Tutorial          By: manaal siddiqui at 2011-11-02 09:38:00

2. Can u show how to do text to speech with servlet.
View Tutorial          By: Rotika at 2011-01-23 20:54:40

3. Great guide. Missed the lecture, and this summed e
View Tutorial          By: Anonymous at 2008-12-21 19:36:19

4. But I have the same error ("javax.net.ssl.SSL
View Tutorial          By: azeemuddin at 2010-03-04 07:25:33

5. public class zcxzcStack
{
//push fun

View Tutorial          By: eissen at 2014-09-22 13:32:20

6. thks for help...
View Tutorial          By: Peps at 2010-01-05 02:28:52

7. hi! i want to know about how database createed in
View Tutorial          By: kundan at 2010-05-19 05:03:33

8. You have no way of knowing when errno was last set
View Tutorial          By: s.b at 2010-05-18 20:54:24

9. Hi,

Just wonder if there is a way t

View Tutorial          By: Bank at 2007-12-18 04:30:26

10. hi.I am new in j2me and really want to learn more
View Tutorial          By: vinoth kumar. A at 2012-10-26 05:20:31