Listing E—db2.jsp


<%@ page language="java" %><%response.setContentType("x-world/x-vrml");%>#VRML V2.0 utf8

<%@ page import="java.sql.*" %>

Viewpoint

{

 position     20 0 50

 orientation 1 0 0 -0.1

 description "Entry"

}

<%

  //Connection strings

  String driver = "oracle.jdbc.driver.OracleDriver";

  String dburl = "jdbc:oracle:thin:@faustus:1521:intra";

  String dbuid = "spheres";

  String dbpwd = "spheres";

  //Define sphere variables

  String color = "";

  String radius = "";

  int sp = 4;

  if (request.getParameter("sp") != null)  {

    sp = Integer.parseInt(request.getParameter ("sp"));

  }

  //Variables:

  String sql = "SELECT * FROM spheres";

  try {

    //Get ResultSet

    Class.forName(driver);

    Connection con = DriverManager.getConnection(dburl, dbuid, dbpwd);

    Statement stmt = con.createStatement();

    ResultSet rs = stmt.executeQuery(sql);

    int count = 0;

    while(rs.next() && count < sp) {

      color = rs.getString("color");

     radius = rs.getString("radius");

%>


    DEF sphere<%=count%> Transform  {

      translation <%=count*15%> 0 0

      children

      [

       Shape {

         appearance Appearance {


          material Material {

           diffuseColor <%=color%>

         }

         }

         geometry Sphere {

          radius <%=radius%>

         }

       }

      ]

    }

<%

    count++;

   }

   stmt.close();

   con.close();

  }catch (java.lang.Exception ex){out.print(ex.toString());}

%>