import java.io.*; import java.sql.*; //import java.sql.SQLException; import javax.servlet.*; //servlet-api.jar (tomcat_5.0.28) import javax.servlet.http.*; //servlet-api.jar (tomcat_5.0.28) import db_provider.*; public class Servlet extends HttpServlet { private ObjectViewer ov = null; private RelationViewer rv = null; private ObjectListViewer olv = null; public void init(ServletConfig config) throws ServletException { try { ov = new ObjectViewer(); rv = new RelationViewer(); olv = new ObjectListViewer(); } catch (Exception ex) { System.err.println("SQLException: " + ex.getMessage()); } } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //String errormessage = null; ResultSet rs = null; //servlet's standard lines response.setContentType("text/html"); PrintWriter out = response.getWriter(); try { //------------------------------------------------------------------ // if parameter is missing and when request.getParameter is inside // try block, an error message is prompted to the browser //------------------------------------------------------------------ String temp_type = request.getParameter("type"); String temp_id = request.getParameter("id"); //search string for object/relation list viewers String search_string = request.getParameter("search"); //convert strings to integer types int type = Integer.valueOf(temp_type).intValue(); int id = Integer.valueOf(temp_id).intValue(); //Metadata Viewer: type 0 if(type == 0) { MetadataViewer mv = new MetadataViewer(); out.println("<html><head><title>Metadata Viewer</title></head><body>"); switch(id) { case 0: out.println("<b>DB Name: </b>" + mv.getDBName()); break; case 1: out.println("<b>DB Size: </b>" + mv.getDBSize()); break; case 2: out.println("<b>DBMS Name: </b>" + mv.getDBMSName()); break; case 3: out.println("<b>JDBC Driver Name: </b>" + mv.getJDBCDriverName()); break; case 4: rs = mv.getTableNames(); out.println("<h3>DB's Tables List</h3>"); out.println("<ol>"); while (rs.next()) { out.println("<li>" + rs.getString(3)); } out.println("</ol>"); rs.close(); break; case 5: rs = mv.getIndexNames(); out.println("<h3>DB's Indexes List</h3>"); out.println("<ol>"); while (rs.next()) { out.println("<li>" + rs.getString(3)); } out.println("</ol>"); rs.close(); break; case 6: out.println("<b>Connection String: </b>" + mv.getConnectionString()); break; case 7: // out.println("<b>Connections Maximum Number: </b>" + mv.getMaxConnections()); break; case 8: out.println("<b>Connection Count: </b>" + mv.getConnectionCount()); break; case 9: out.println("<b>User Count: </b>" + mv.getUserCount()); break; case 10: out.println("<b>CPU Used: </b>" + mv.getCPUUsed()); break; case 11: out.println("<b>Memory Used: </b>" + mv.getMemoryUsed()); break; } out.println("</body></html>"); } //Object Viewer: type 1 if(type == 1) { rs = ov.getObjectProperties(id); //4834 out.println("<html><head><title>Object Viewer</title></head><body>"); String output = "<table border>"; output = output + "<tr><td>Property Name</td><td>Property Value</td></tr>"; while (rs.next()) { String sValue1 = rs.getString("spropertyname"); String sValue2 = rs.getString("spropertyvalue"); output = output + "<tr>" + "<td>" + sValue1 + "</td>" + "<td>" + sValue2 + "</td>" +"</tr>"; } output = output + "</table></body></html>"; out.println(output); } //Relation Viewer: type 2 if(type == 2) { rs = rv.getRelationProperties(id); //1000125229 out.println("<html><head><title>Relation Viewer</title></head><body>"); String output = "<table border>"; output = output + "<tr><td>Property Name</td><td>Property Value</td></tr>"; while (rs.next()) { String sValue1 = rs.getString("spropertyname"); String sValue2 = rs.getString("spropertyvalue"); output = output + "<tr>" + "<td>" + sValue1 + "</td>" + "<td>" + sValue2 + "</td>" +"</tr>"; } output = output + "</table></body></html>"; out.println(output); } //Object List Viewer: type 3 if(type == 3) { rs = olv.getObjectList(search_string); //ZNF out.println("<html><head><title>Object List Viewer</title></head><body>"); String output = "<table border>"; output = output + "<tr><td>Name</td><td>Alias</td><td>Description</td><td>LocusLink ID</td><td>Unigene ID</td></tr>"; while (rs.next()) { String sValue1 = rs.getString("name"); String sValue2 = rs.getString("alias"); String sValue3 = rs.getString("description"); String sValue4 = rs.getString("locuslinkid"); String sValue5 = rs.getString("unigeneid"); output = output + "<tr><td>" + sValue1 + "</td><td>" + sValue2 + "</td>"; output = output + "<td>" + sValue3 + "</td><td>" + sValue4 + "</td>"; output = output + "<td>" + sValue5 + "</td></tr>"; } output = output + "</table></body></html>"; out.println(output); } } catch(Exception e) { out.println("<html>" + "<head><title>" + "DB: Error" + "</title></head>\n<body>" + "<p>SQL error in doGet: " + e.getMessage() + "</p></body></html>"); return; } out.close(); } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here