<%@ page import="java.sql.*" %> <html> <body> <% String url = "jdbc:oracle:thin:@//localhost:1521/XE"; String user = "system"; String password = "abhi"; Connection conn = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection(url, user, password); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM employee"); while (rs.next()) { %> <p>User: <%= rs.getString("ename") %></p> <% } } catch (Exception e) { out.println("Error: " + e.getMessage()); } finally { if (conn != null) conn.close(); } %> </body> </html>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter