JSP with ms-access database getting problem with column
I have coded JSP that retrieve the column from one table. But i could not get the column values as I like .Would you, any one help me to solve the problem. And also , how can DAO be used in role seperation in MVC pattern in my project. My project is involved with Customer relation Management and Office automation in JSP and Servlet
Thank you very much .
this s code . it database name aliens.
it will retrieve the data form the table " customer"
<%@ page language="java" import="java.util.*, java.sql.*, java.io.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<!-- Created with the CoffeeCup HTML Editor 2006 -->
<!--http://www.coffeecup.com/-->
<!--Brewed on 8/10/2006 2:17:31 PM -->
<head>
<title>sample</title>
<meta name="generator" content="CoffeeCup HTML Editor 2006 - www.coffeecup.com">
<meta name="description" content="">
<meta name="keywords" content="">
</head>
<body bgcolor="green" text="White" link="#BBaaFF" vlink="#800080" alink="#FF0000">
<font size=10 > hi Warm welcome to this page
<%! String str=" name is displayed thru expression" ;%>
<%= str %>
<%String name = "muralidharan";
out.println(name); %>
<%
out.println(new java.util.Date().toString());
%>
<h3>This is the page which can be used to retrieve the information about the customers.</h3>
<!-- Set the scripting language to java and -->
<!-- import the java.sql package -->
<% String str="Hi"; %>
<%=str%>
<%
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
System.out.println("Driver is registered");
con =DriverManager.getConnection("jdbc:odbc:Aliens");
Statement statement = con.createStatement();
System.out.println("Jsp in connecting to Databse");
ResultSet rs = statement.executeQuery("SELECT * " +
"FROM customer");
%>
The information about the customers are displaying
The information is got from the datasource aliens
<!-- Add an HTML table to format the results -->
<TABLE BORDER="1">
<TR>
<TH>SerialNo</TH><TH>Date</TH><TH>Month</TH><TH>Firstname</TH><TH>LastName</TH><TH>Contact no </TH><TH>Mobileno</TH><TH>email</TH><TH>Need</TH><TH>Callername</TH>
<%
while ( rs.next() ) {
out.println("<TR>\n<TD>" + rs.getInt("seial_no")
+ "</TD>");
out.println("<td>"+rs.getInt("Date")+"</td>");
out.println("<TD>" + rs.getString("month") + "</TD>");
out.println("<TD>" + rs.getInt("year") + "</TD>");
out.println("<TD>" + rs.getString("first_name") + "</TD>");
out.println("<TD>" + rs.getString("last_name") + "</TD>");
out.println("<TD>" + rs.getInt("landline") + "</TD>");
out.println("<TD>" + rs.getLong("mobileno") + "</TD>");
out.println("<TD>" + rs.getString("email") + "</TD>");
out.println("<TD>" + rs.getString("need") + "</TD>");
out.println("<TD>" + rs.getString("caller_name") + "</TD>\n</TR>");
}
rs.close();
}
catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
catch (ClassNotFoundException cnfe) {
System.err.println(cnfe.getMessage());
}
catch (Exception e) {
System.err.println(e.getMessage());
}
finally {
try {
if ( con != null ) {
// Close the connection no matter what
con.close();
System.err.println(" The connecion is closing down from the database source");
}
}
catch (SQLException sqle) {
System.err.println(sqle.getMessage());
}
}
%>
</body>
</html>