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. @Brian You surely can deploy your server code clas
View Tutorial          By: Ayush at 2013-06-10 13:22:38

2. Thank you for this tutorial. Thank you all the mor
View Tutorial          By: sd at 2013-09-09 05:38:52

3. u said that const function cant change object.can
View Tutorial          By: z at 2010-05-09 12:02:17

4. public class zcxzcStack
{
//push fun

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

5. int n = 0;
for (int m = 0; m < 5; m++) {

View Tutorial          By: max at 2011-05-26 09:41:26

6. Hi,

Are you getting any specific er

View Tutorial          By: Norman Chap at 2008-12-04 02:42:47

7. hi,
when i run the code i got the exception

View Tutorial          By: arjun at 2014-09-18 10:25:18

8. the code works fine. you just need to create a mai
View Tutorial          By: Nabil at 2011-08-09 11:11:03

9. Your page does not show the text in the proper col
View Tutorial          By: Warron at 2013-04-04 17:50:22

10. hello can u send me the code in java to send and r
View Tutorial          By: somanath at 2011-02-17 01:28:40