troubleshooting Question

jdbc setup in code

Avatar of annie613
annie613 asked on
Java
7 Comments1 Solution269 ViewsLast Modified:
is there something missing in my code. i have a class to set up my jdbc connections to my db

public class aug
{
  //privarte variables
  private Connection conn = null;
  private DataSource ds = null;
  private PreparedStatement ps = null;
  private ResultSet rs = null;
  private static final String dataSource = "jdbc/aug";
  private String message = "";
 

  public static final String getTypeQuery =
    "select TYPE_DESC from TYPE where ACTIVE_FLAG = 1";
 
  public ArrayList getType()
  {
    ArrayList TypeList = new ArrayList();

    try
    {
      makeConnection();
      ps = conn.prepareStatement(getTypeQuery);
      rs = (ResultSet)ps.executeQuery();
     
      while (rs.next())
      {
        TypeList.add(rs.getString("TYPE_DESC"));
      }//while
      rs.close();
    }//try
    catch (Exception e)
    {
      System.out.println("exception for getType(): " + e.toString());
    }//catch
    finally
    {
      try
      {
        releaseConnection();
      }
      catch (Exception e){}
    }//finally
    System.out.println("TypeList = " + TypeList);
    return miprTypeList;
  }//getType

  private void makeConnection() throws Exception
  {
    try
    {
      if (conn != null)
      {
        conn.close();
      }
      InitialContext ic = new InitialContext();
      DataSource ds = (DataSource) ic.lookup(dataSource);

      conn = ds.getConnection();
    }//try
    catch (Exception ex)
    {
      throw new Exception("Unable to connect to database. " + ex.getMessage());
    }//catch
  }//makeConnection

  private void releaseConnection() throws Exception
  {
    try
    {
      if (ps != null)
      {
        ps.close();
      }
     
      if (rs != null)
      {
        rs.close();
      }
     
      if (conn != null)
      {
        conn.close();
      }
    } //try
    catch (SQLException ex)
    {
      throw new Exception("releaseConnection: " + ex.getMessage());
    }//catch
  }//releaseConnection
 
}//aug

and i have a jsp file to display my arrayList
<%@ page contentType="text/html;charset=windows-1252"%>

<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page errorPage="error.jsp"%>

<jsp:useBean id='in' scope='page' class='aug.aug'/>


<%
  String pageTitle = "Search By:";
  response.setHeader("Pragma", "no-cache");
  response.setHeader("Cache-Control", "no-cache, post-check=0, pre-check=0");

  ArrayList TypeList = in.getType();
%>

<html>

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Search</title>
    <link href="./css/aug.css" rel="stylesheet" media="screen"/>

  </head>
 
  <body>
    <form name="search" id="search" action="display.jsp" method="POST" onsubmit="return validateFormData();">

      <DIV align="center">
        <hr/><br>
      <table cellspacing="2" cellpadding="3" border="1" width="41%">
       
 
          <tr>
            <td width="23%">TYPE</td>
            <td width="77%" style="font-size:x-small;">
              <select name="type">
              <%for (int typectr = 0; typectr < TypeList.size(); typectr++)
              {%>
              <option value="<%=TypeList.get(typectr)%>"><%=TypeList.get(typectr)%></option>
              <%}%>
              </select> &nbsp;*one type must always be selected
            </td>
          </tr>
       
     
     
      <P align="center">
        <input type="submit" value="Search" name="Search"/>
        <input type="reset" value="Reset" name="Reset"/>
      </P>
      <hr/>
     
      </form>

    TypeList=  <%=TypeList%>

  </body>
 
</html>

when i compile the files --- all runs well -- my jsp page displays but then i get an exception

exception for getTypeQuery: java.lang.Exception: Unable to connect to database. jdbc/aug not found
but i know my DB is running ---- am i missing something in my code or the setup of the workspace that it wont display??

any suggestions? thanks in advance! cheers annie
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros