Filling a Table
<%@ page import="java.sql.*" %>
<HTML>
<HEAD>
<TITLE>Filling a Table</TITLE>
</HEAD>
<BODY>
<H1>Filling a Table</H1>
<%
Connection connection = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:data", "userName", "password");
Statement statement = connection.createStatement();
String command = "INSERT INTO Employees (ID, Name) VALUES (1, 'Joe')";
statement.executeUpdate(command);
command = "INSERT INTO Employees (ID, Name) VALUES (2, 'Yin')";
statement.executeUpdate(command);
ResultSet resultset =
statement.executeQuery("select * from Employees");
while(resultset.next()){
%>
<TABLE BORDER="1">
<TR>
<TH>ID</TH>
<TH>Name</TH>
</TR>
<TR>
<TD> <%= resultset.getString(1) %> </TD>
<TD> <%= resultset.getString(2) %> </TD>
</TR>
</TABLE>
<%
}
%>
</BODY>
</HTML>
Related examples in the same category