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



Related Tutorials

Java program to get location meta data from an image

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

Archived Comments

1. To 15:
Sometimes it is useful to return the

View Tutorial          By: Anderson Goulart at 2010-08-24 19:15:14

2. its not working.
View Tutorial          By: raja at 2012-08-29 11:44:45

3. If you are working with the multi-threaded program
View Tutorial          By: Prithvi at 2010-01-07 10:24:12

4. Is it possible to create a Reader class without lo
View Tutorial          By: bs at 2010-10-11 05:42:34

5. This program is mush faster and finer than given p
View Tutorial          By: Anonymous at 2013-02-27 05:38:27

6. Hi
I am newly in java. I have one dought. I

View Tutorial          By: Saman at 2010-08-03 20:34:38

7. Very well explained Thanks.
View Tutorial          By: Anthony at 2012-12-12 00:20:39

8. Hi all
I connected my mobile wi

View Tutorial          By: sruthy at 2010-07-07 03:44:27

9. thanks a lot ..
View Tutorial          By: indra at 2009-03-25 15:40:03

10. Very nice tutorial........
View Tutorial          By: Santosh Saha at 2010-04-11 05:58:51