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. /* getword: get next word or character from input
View Tutorial          By: Vinod S at 2011-12-02 07:53:52

2. i have to learn java
View Tutorial          By: md arif alam at 2013-04-15 18:30:27

3. hi,
i am safeer, i am try this program in

View Tutorial          By: Safi at 2009-05-22 22:32:04

4. The example shown and ur way of explaining is good
View Tutorial          By: Devi at 2009-02-24 07:19:26

5. Thank you very much for explaning the things in su
View Tutorial          By: Sunil Yadav at 2010-05-27 04:04:31

6. Good one.........!!!
View Tutorial          By: Shailesh Nakade at 2012-07-11 09:48:33

7. hi please help me out.. how to use this card for r
View Tutorial          By: sasivarnan at 2011-04-27 15:01:12

8. Hallo every one. I am working on my project in j2m
View Tutorial          By: radhe at 2010-12-14 08:08:25

9. sir i want this following pattern using loops

View Tutorial          By: teju at 2015-09-13 22:46:58

10. the example is from herbert schildt complete ref..
View Tutorial          By: dui_prithibi at 2012-11-26 12:59:15