<%@ page import="java.sql.*" %> Simple JSP/Oracle Query Example
Employees

<% Connection conn = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection("jdbc:oracle:thin:@fuju.exzilla.net:1521:fuju","scott","tiger"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM scott.employees"); //Print start of table and column headers out.println(""); 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(""); } out.println("
IDNAMESURNAMESALARYSTARTDATE
" + rs.getString("EMPID") + "" + rs.getString("ENAME") + "" + rs.getString("ESURNAME") + "" + rs.getInt("SALARY") + "" + rs.getString("STARTDATE") + "
"); } 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) {} } } %>