package wasdev.sample.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

/**
 * Servlet implementation class SimpleServlet
 */
@WebServlet("/SimpleServlet")
public class SimpleServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           response.setContentType("text/html");
 //       response.getWriter().print("Hello World!");
        
        Context initContext;
		try {
			initContext = new InitialContext();
			DataSource ds = (DataSource)initContext.lookup("jdbc/kim-dashDB for Analytics-7n");
			Connection conn = ds.getConnection();
		//	System.out.println("yes");
			 response.getWriter().print("DashDB is connected now!</br>");
		    Statement stmt = conn.createStatement();
          
		    //stmt.execute("DELETE FROM CUSTOMERS WHERE ID = 7");
		    //stmt.execute("INSERT INTO CUSTOMERS VALUES (7, 'Muffy', 24, 'Indore', 10000.00 )");
		    //stmt.executeQuery("SELECT * FROM CUSTOMERS");
			
		    stmt.execute("DELETE FROM DOGS WHERE ID = 7");
		    stmt.execute("INSERT INTO DOGS VALUES (7, 'NEW', 6, 'NEW', 100.00 )");
                    stmt.executeQuery("SELECT * FROM DOGS");

		    ResultSet rs = stmt.getResultSet();
		    System.out.println("yes");
	           while(rs.next()) {
                             response.getWriter().print(rs.getString(2)+"  "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5)+"</br>");
			} 
			stmt.close();
			conn.close();
		} catch (NamingException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }

}

@@ -1262,11 +1262,17 @@
 ;%0A%09%09
+       
 //
-%09
 Syst
@@ -1357,24 +1357,111 @@
 !%3C/br%3E%22);%0A%09%09
+%09 response.getWriter().print(%22%3C/br%3EDogs table: NAME, AGE, DOGTYPE, COST%3C/br%3E%22);%0A%09%09     
     Statemen
@@ -1506,24 +1506,27 @@
      %0A%09%09    
+ 
+  
 //stmt.execu
@@ -1565,32 +1565,35 @@
 ID = 7%22);%0A%09%09    
+   
 //stmt.execute(%22
@@ -1664,24 +1664,27 @@
  )%22);%0A%09%09    
+   
 //stmt.execu
@@ -1725,20 +1725,17 @@
 ;%0A%09%09%09%0A%09%09
-    
+%09
 stmt.exe
@@ -1775,24 +1775,28 @@
  7%22);%0A%09%09    
+  
+  
 stmt.execute
@@ -1866,32 +1866,36 @@
                 
+    
 stmt.executeQuer
@@ -1926,16 +1926,20 @@
 %0A%0A%09%09    
+    
 ResultSe
@@ -1972,43 +1972,47 @@
 ;%0A%09%09
-    System.out.println(%22yes%22
+%09ResultSet rs = stmt.getResultSet(
 );%0A%09
-   
+%09
     
@@ -2034,22 +2034,16 @@
 xt()) %7B%0A
-      
         

Update SimpleServlet.java