package wasdev.sample.servlet;

import java.io.IOException;
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 java.sql.Connection;
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 TEST WHERE ID = 2");
		    stmt.execute("INSERT INTO TEST VALUES (7, 'Muffy', 24, 'Indore', 10000.00 )");
                    stmt.executeQuery("SELECT * FROM TEST");
		      // stmt.execute("INSERT INTO DOGS VALUES ('meo1', 'husky' )");
		 //   stmt.execute("INSERT INTO DOGS VALUES ('meo2', 'husky' )");           
		//    stmt.executeQuery("SELECT * FROM DOGS WHERE dalmatian = 'husky'");
			
		    ResultSet rs = stmt.getResultSet();
		    System.out.println("yes");
	           while(rs.next()) {
                         response.getWriter().print(rs.getString(1)+"  "+rs.getString(2)+"</br>");
			} 
			stmt.close();
			conn.close();
		} catch (NamingException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

    }

}

@@ -64,38 +64,27 @@
 ort java
-x
 .s
-ervlet.ServletExcep
+ql.Connec
 tion;%0Aim
@@ -96,76 +96,20 @@
 java
-x
 .s
-ervlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServl
+ql.ResultS
 et;%0A
@@ -123,90 +123,26 @@
 java
-x
 .s
-ervlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A
+ql.SQLException;
 %0Aimp
@@ -150,35 +150,35 @@
 rt java.sql.
-Connection;
+Statement;%0A
 %0Aimport java
@@ -512,16 +512,17 @@
 Source;%0A
+%0A
 /**%0A * S
@@ -1523,17 +1523,17 @@
 VALUES (
-7
+2
 , 'Muffy
@@ -1976,32 +1976,49 @@
                 
+                 
 response.getWrit
@@ -2045,13 +2045,53 @@
 ing(
-1)+%22 
+2)+%22  %22+rs.getString(3)+%22 %22+rs.getString(4)+%22
  %22+r
@@ -2102,17 +2102,17 @@
 tString(
-2
+5
 )+%22%3C/br%3E
@@ -2264,16 +2264,19 @@
 race();%0A
+%09%09%7D
 %0A    %7D%0A%0A

Update SimpleServlet.java