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. Hello, I have been using a very similar code on de
View Tutorial          By: Rod at 2011-11-13 15:09:52

2. great solution and brief explanation, love it.
View Tutorial          By: habesha at 2011-12-02 16:14:45

3. javax.comm.NoSuchPortException
at j

View Tutorial          By: das at 2011-10-20 15:21:05

4. can you plase give an exmple of what should i put
View Tutorial          By: Or at 2013-02-16 11:32:17

5. very easy explain
View Tutorial          By: Rohit Bhojani at 2012-04-10 12:49:20

6. hope this may help u

class product<

View Tutorial          By: princess at 2011-11-30 12:11:57

7. Sir please can you tell me that how can i find occ
View Tutorial          By: Saad at 2013-01-20 11:14:39

8. This isn't entirely correct. A class can be abstra
View Tutorial          By: Jay at 2013-01-30 14:52:15

9. The !isset() is basically checking if the string i
View Tutorial          By: Bijan at 2012-09-21 20:49:41

10. how to run this program? give sample code to cre
View Tutorial          By: meena at 2012-01-12 11:52:03