<%@ page import="java.sql.*" %> JSP Database Connectivity
Database: SQL on Server
<% Connection conn = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection( "jdbc:odbc:orcl","java","gosling"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM dept order by dname"); //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("
NamePhoneAddress
" + rs.getString("deptno") + "" + rs.getString("dname") + "" + rs.getString("loc") + "
"); conn.close(); } 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() + "
"); } %>