<%@ page import="java.sql.*" %> Simple JSP/Oracle Query Example
Product - WT Part Number

<% Connection conn = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection("jdbc:oracle:thin:@LarrySERVER:1521:wind","system","manager"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select NAME,WTPARTNUMBER from WCUSER.WTPRODUCTMASTER"); //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("
NAMEWTPARTNUMBER
" + rs.getString("NAME") + "" + rs.getString("WTPARTNUMBER") + "
"); } 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) {} } } %>