List:Commits« Previous MessageNext Message »
From:tony.bedford Date:July 2 2010 4:28pm
Subject:svn commit - mysqldoc@docsrva: r21573 - in trunk/sample-programs/connector-j-tutorials: . HelloWebApp
View as plain text  
Author: tbedford
Date: 2010-07-02 18:28:56 +0200 (Fri, 02 Jul 2010)
New Revision: 21573

Log:
Initial JSP app to connect to database via Glassfish

Added:
   trunk/sample-programs/connector-j-tutorials/HelloWebApp/index.jsp


Added: trunk/sample-programs/connector-j-tutorials/HelloWebApp/index.jsp
===================================================================
--- trunk/sample-programs/connector-j-tutorials/HelloWebApp/index.jsp	                        (rev 0)
+++ trunk/sample-programs/connector-j-tutorials/HelloWebApp/index.jsp	2010-07-02 16:28:56 UTC (rev 21573)
Changed blocks: 1, Lines Added: 39, Lines Deleted: 0; 1185 bytes

@@ -0,0 +1,39 @@
+<%@ page import="java.sql.*, javax.sql.*, java.io.*, javax.naming.*" %>
+<html>
+<head><title>Hello world from JSP</title></head>
+<body bgcolor="white">
+<img src="images/duke.waving.gif"> 
+<%
+  InitialContext ctx;
+  DataSource ds;
+  Connection conn;
+  Statement stmt;
+  ResultSet rs;
+
+  try {
+    ctx = new InitialContext();
+    ds = (DataSource) ctx.lookup("java:comp/env/jdbc/MySQLDataSource");
+    conn = ds.getConnection();
+    stmt = conn.createStatement();
+    rs = stmt.executeQuery("SELECT * FROM Country");
+
+    while(rs.next()) {
+%>
+    <h3>Name: <%= rs.getString("Name") %></h3>
+    <h3>Population: <%= rs.getString("Population") %></h3>
+<%    
+    }
+  }
+  catch (SQLException se) {
+%>
+    <%= se.getMessage() %>
+<%      
+  }
+  catch (NamingException ne) {
+%>  
+    <%= ne.getMessage() %>
+<%
+  }
+%>
+</body>
+</html>


Thread
svn commit - mysqldoc@docsrva: r21573 - in trunk/sample-programs/connector-j-tutorials: . HelloWebApptony.bedford2 Jul