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. Good Tutorial.
Thanks.

View Tutorial          By: Oki Wicaksono at 2012-05-29 04:09:05

2. You saved my but by posting this. Thank You. I j
View Tutorial          By: cranakis at 2014-09-19 16:10:20

3. Thnaks a lot. Deep in brief.
View Tutorial          By: Thanks at 2012-05-23 03:36:37

4. excellent explanation...............Thanks for mak
View Tutorial          By: Kiran Leo at 2012-12-08 06:41:26

5. Im using maxis broadband now.
I want to cre

View Tutorial          By: rayminn at 2012-06-03 21:08:13

6. Does not work.
View Tutorial          By: Hallo at 2012-10-25 09:50:05

7. HI,
I am getting this error
Error lo

View Tutorial          By: vijay bhanu at 2009-07-18 08:57:57

8. 1
View Tutorial          By: hamza at 2015-06-08 15:09:29

9. How to download more than one files. If I use for
View Tutorial          By: Riyas at 2012-01-08 07:55:03

10. So I appreciate this website, however... would it
View Tutorial          By: Christina at 2013-02-06 16:46:12