<%@ page import="java.sql.*" %> JSP Database Connectivity
Register Table
<% String user = (String)session.getAttribute("user"); String passwd = (String)session.getAttribute("passwd"); Connection conn = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:orcl",user,passwd); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM register order by name"); //Print start of table and column headers out.println(""); out.println(""); //Loop through results of query. while(rs.next()) { out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); } out.println("
NAMEPHONEDATEFEES
" + rs.getString("name") + "" + rs.getString("phone") + "" + rs.getDate("rdate") + "" + rs.getString("fees") + "
"); } catch(SQLException e) { out.println("SQLException: " + e.getMessage() + "
"); while((e = e.getNextException()) != null) out.println(e.getMessage() + "
"); } catch(ClassNotFoundException e) { out.println("ClassNotFoundException: " + e.getMessage() + "
"); } finally { //Clean up resources, close the connection. if(conn != null) { try { conn.close(); } catch (Exception ignored) {} } } %>