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

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

Java program to check if user input is an even number

Archived Comments

1. The following line in the code
((NewThread)

View Tutorial          By: Carlos at 2009-11-18 14:34:51

2. Hi , instead of using localhost. I am using a mobi
View Tutorial          By: ashish at 2011-02-28 05:05:49

3. Dear Samantha, Thx for pointing the extra \. I hav
View Tutorial          By: Emiley at 2011-06-06 04:50:40

4. why do't you create ActionErrors object like this<
View Tutorial          By: veera reddy at 2011-07-15 12:14:57

5. Hi

Can you anyone please post me th

View Tutorial          By: Damodhar at 2009-05-06 04:12:33

6. It worked. Thank U!
View Tutorial          By: Abhijit Kurane at 2010-12-27 11:01:48

7. the above code works fine for. May someone help wi
View Tutorial          By: T.T at 2012-02-23 06:22:36

8. pls send more tutorial on my id
View Tutorial          By: vipin at 2012-11-17 07:23:49

9. Microsoft VB.net 2008 not showing Crystal Report V
View Tutorial          By: Ali at 2011-11-30 03:21:00

10. By running ListPorts, I am not getting any output
View Tutorial          By: Srinivasa Rao at 2009-04-02 05:17:20