Ok folks.... I just created a solution that queries an Access Database. It is a
JSP file that uses Javabean methods to query the database and get values. I would
like feedback on improving the design or it could be used as a reference for an
aspiring JSP user.
Note: I used the jdbc-odbc bridge. If one is planning on using JDBC it is best to
use another driver.
The table is a Document Type Table with a TYPE_ID, DOC_TYPE, DOC_DESCRIPTION.
Pedro
=========================== JSP FILE ==============================
<html>
<body bgcolor="white">
<jsp:useBean id="foo" scope="session" class="checkbox.Doc_Types" />
<% foo.getRecords(); %>
<hr><center><font face="verdana"><h2>Doc Type Table</h2>
<form action="update_Doc_Type.jsp">
<TABLE border=1 cellpadding=3 cellspacing=2>
<TR><TD bgcolor="white"><B><font face="verdana" color="red">Delete</TD><TD
bgcolor="navy"><font face="verdana" color="white">Type ID</TD><TD
bgcolor="navy"><font face="verdana" color="white">DOC TYPE</TD><TD
bgcolor="navy"><font face="verdana" color="white">DOC DESCRIPTION</TD></TR>
<% while (foo.nextRecord() == true) { %>
<TR><input type="hidden" name="Doc_Type_ID" value="<%=foo.getType_ID()%>">
<td><center><input type="checkbox" name="delete_<%=foo.getType_ID()%>"
value="Y"></td>
<TD><font face="verdana"><%= foo.getType_ID() %></TD>
<TD><font face="verdana"><%= foo.getDoc_Type() %></TD>
<TD><font face="verdana"><%= foo.getDoc_Desc() %></TD>
<%}%>
</TR>
</TABLE><BR><BR><BR>
<INPUT TYPE="Submit" VALUE="SUBMIT"> <INPUT TYPE=RESET VALUE="CLEAR">
</form>
</font>
</body>
</html>
=========================== JavaBean File =================================
package checkbox;
import java.io.*;
import java.sql.*;
import sun.jdbc.odbc.*;
public class Doc_Types {
int type_id;
String doc_type;
String doc_desc;
ResultSet rs;
// Get Database Records
public void getRecords() {
String url = "jdbc:odbc:pit";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Driver driver = new sun.jdbc.odbc.JdbcOdbcDriver();
} catch(Exception ee) {
System.out.println(ee.getMessage());
}
try {
java.sql.Connection con =
DriverManager.getConnection(url,"admin", "pit");
con.setAutoCommit(false);
java.sql.Statement stmt = con.createStatement();
String query;
query = "SELECT * from DOC_TYPES";
rs = stmt.executeQuery(query);
type_id = rs.getInt("TYPE_ID");
doc_type= rs.getString("DOC_TYPE");
doc_desc= rs.getString("TYPE_DESCRIPTION");
} catch (SQLException e) {
System.err.println("SQLException: " + e.getMessage());
}
}
// Get the next Database record. Returns true or false if there are more
public boolean nextRecord() {
boolean check;
try {
check=rs.next();
type_id = rs.getInt("TYPE_ID");
doc_type= rs.getString("DOC_TYPE");
doc_desc= rs.getString("TYPE_DESCRIPTION");
return check;
}
catch (SQLException e) {
System.err.println("SQLException: " + e.getMessage());
}
return false;
}
public int getType_ID() {
return type_id;
}
public String getDoc_Type() {
return doc_type;
}
public String getDoc_Desc() {
return doc_desc;
}
}
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets