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 sir
View Tutorial          By: vinay at 2012-01-28 12:38:30

2. Great tutorial. Thanks guys.
View Tutorial          By: John D at 2009-03-21 11:01:58

3. how to show text in tab menu & when i selected
View Tutorial          By: shadah at 2012-05-05 14:14:37

4. i need some simple java programs
View Tutorial          By: ramya at 2009-11-24 04:25:07

5. Hello Sir,

Is there a way to use JS

View Tutorial          By: rohit at 2008-04-02 09:07:41

6. thank you for your excellent explaination..! :)
View Tutorial          By: marios at 2012-05-16 16:17:31

7. really nice
View Tutorial          By: umer at 2011-06-25 06:35:19

8. Thanks. What datatype can we give to a variable St
View Tutorial          By: Bafokeng Lebesa at 2012-11-27 12:35:40

9. Thanks very much, this helped alot.
View Tutorial          By: Steve at 2012-10-09 21:09:16

10. Great!! But when I use wscompile to create stub,I
View Tutorial          By: Baven at 2008-07-22 15:55:52