Compilation problem (cannot resolve symbol)

I have searched the Forums for "cannot resolve symbol" and as usual, many posts with no answers or just advise that noone ever comes back to say works. I am trying to compile this code:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import org.acme.*;
public class HelloOpenEJB extends HttpServlet {
String factory = "org.openejb.client.LocalInitialContextFactory";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
PrintWriter out = response.getWriter();
try{
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, factory );
InitialContext ctx = new InitialContext( p );
//Lookup the bean using it's deployment id
Object obj = ctx.lookup("/Hello");
HelloHome ejbHome = (HelloHome) obj;
//Use the HelloHome to create a HelloObject
HelloHome ejbHome = (HelloHome)
PortableRemoteObject.narrow(obj, HelloHome.class);
//The part we've all been wainting for...
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>"+ ejbObject.sayHello() +"</h1>");
out.println("</body>");
out.println("</html>");
} catch (Exception e){
response.setContentType("text/plain");
e.printStackTrace(out);
I'm running this on a Linux box. When I compile, I get this:
HelloOpenEJB.java:28: ejbHome is already defined in doGet(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
HelloHome ejbHome = (HelloHome)
^
HelloOpenEJB.java:29: cannot resolve symbol
symbol : variable PortableRemoteObject
location: class HelloOpenEJB
PortableRemoteObject.narrow(obj, HelloHome.class);
^
HelloOpenEJB.java:38: cannot resolve symbol
symbol : variable ejbObject
location: class HelloOpenEJB
out.println(""+ ejbObject.sayHello() +"");
^
3 errors
I don't know why any of these errors are occuring, besides the obvious responses given back from javac, so can someone help? Thanks, Jeremy

The error message "x already defined in y" means that you're trying to use a name that already exists in the current scope. In your case you have:
HelloHome ejbHome = (HelloHome) obj;
//Use the HelloHome to create a HelloObject
HelloHome ejbHome = (HelloHome)
PortableRemoteObject.narrow(obj, HelloHome.class);Here you are trying to declare two instances of HelloHome with the same name.
The reason that you would get "cannot resolve symbol" is that you are trying to access a variable or class that you haven't declared or imported.

Similar Messages

  • JSP Compilation Problem - Cannot Resolve Symbol

    I cannot see the problem. Maybe I am not sober at 2:30 am.
    <%
    Collection postBeans = ( Collection )request.getAttribute( "PostBeans" );
    Iterator iterator = postBeans.iterator();
    int i = 0;
    while( iterator.hasNext() )
          PostBean postBean = (PostBean)iterator.next();
       i++;
       String background;
       if ( postBean.getParentPostID() == 0 )
          background = "#FFCE9C";
       else
          if ( ( i%2 ) != 0 )
             background = "#EEEEEE";
          else
             background = "#FFFFFF";
    %>
    <table width="95%" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#999999">
      <tr bgColor=<%=background%>>
      </tr>
    </table>I got compilation error: cannot resolve symbol
    symbol: background

    I put the variable 'background' outside the while loop. The 'cannot resolve symbol' problem is gone. But, I got another compilation error:
    >
    unexpected type
    required: variable
    found : value
    out.write("\r\n }\r\n i++;\r\n if ( postBean.getParentPostID() == 0 ) \r\n {\r\n background = \"#FFCE9C\";\r\n }\r\n else \r\n {\r\n if ((i%2) != 0) \r\n {\r\n background = \"#EEEEEE\";\r\n } \r\n else \r\n {\r\n background = \"#FFFFFF\";\r\n }\r\n }\r\n%>\r\n");
    The code looks like:
    <%
    String background;
    Collection postBeans = ( Collection )request.getAttribute( "PostBeans" );
    Iterator iterator = postBeans.iterator();
    int i = 0;
    while( iterator.hasNext() )
          PostBean postBean = (PostBean)iterator.next();
       i++;
       if ( postBean.getParentPostID() == 0 )
          background = "#FFCE9C";
       else
          if ( ( i%2 ) != 0 )
             background = "#EEEEEE";
          else
             background = "#FFFFFF";
    %>
    <table width="95%" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#999999">
      <tr bgColor=<%=background%>>
      </tr>
    </table>

  • Newbie problem: "cannot resolve symbol"

    I'm working through some tutorials but I get errors even if i get the code CORRECT or I should say identical to the source code displayed on the web. For instance i get this:
    E:\Java\New>javac SwingUI.java
    SwingUI.java:41: not a statement
              WindowListener 1 = new WindowAdapter() {
    ^
    SwingUI.java:41: ';' expected
              WindowListener 1 = new WindowAdapter() {
    ^
    SwingUI.java:4: cannot resolve symbol
    symbol : class ActionListener
    location: class SwingUI
    class SwingUI extends JFrame implements ActionListener {
    ^
    SwingUI.java:25: cannot resolve symbol
    symbol : class ActionEvent
    location: class SwingUI
         public void actionPerformed(ActionEvent event){
    ^
    SwingUI.java:15: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (SwingUI)
              button.addActionListener(this);
    ^
    SwingUI.java:18: cannot resolve symbol
    symbol : class Borderlayout
    location: class SwingUI
              panel.setLayout(new Borderlayout());
    ^
    SwingUI.java:46: addWindowListener(java.awt.event.WindowListener) in java.awt.Window cannot be applied to (int)
              frame.addWindowListener(1);
    ^
    SwingUI.java:48: cannot resolve symbol
    symbol : variable set
    location: class SwingUI
              frame.set.Visible(true);
    ^
    8 errors
    The beginning of the code is:
    import java.awt.Color;
    import java.awt.BorderLayout;
    import java.awt.event.*;
    import javax.swing.*;
    class SwingUI extends JFrame implements ActionListener {
         JLabel text, clicked;
         JButton button, clickButton;
         JPanel panel;
         private boolean _clickMeMode = true;
         SwingUI(){
              text=new JLabel("I'm a simple program");
              button= new JButton("Click here!");
              button.addActionListener(this);
              panel =new JPanel();
              panel.setLayout(new Borderlayout());
              panel.setBackground(Color.white);
              getContentPane().add(panel);
              panel.add(BorderLayout.CENTER, text);
              panel.add(BorderLayout.SOUTH, button);
    To me it seems as if there is a problem with my environmental settings and/or with the "import" files, but wouldn't that yield different error messages?
    I'm running j2sdk1.4.0_01 on windows2000 professional
    I should say that simple programs compile without errors.
    thx
    /Hans

    The letter 'l' is very similar to the number 1 in certain fonts unfortunately.
    /Hans

  • Compiling error - cannot resolve symbol

    Hi,
    I am working on writing out this basic code for a project. When I compile, I get an error "Cannot resolve symbol" for the gpa variable. Please help!
    My intention is to use the hours and points from the crHours and nbrPoints methods, and use them to calculate GPA in the grPtAvg method:
    public class Student
         public static void main(String[]args)
    idNum();
    crHours();
    nbrpoints();
    gpa = grPtAvg(hours, points);
    System.out.println("Student's GPA is " + gpa);
    public static void idNum()
    int id = 2520;
    System.out.println("Student's ID is " + id);
    public static float crHours()
    float hours = 5;
    System.out.println("Student's credit hours are " + hours);
    return hours;
    public static float nbrpoints()
    float points = 22;
    System.out.println("Student's earned points are " + points);
    return points;
    public static float grPtAvg(float hours, float points)
    float gpa;
    gpa = points / hours;
    System.out.println("Student's computed GPA is " + gpa);
    return gpa;

    That's because you're doing the same thing (in a somewhat different way) with those.
    The variables: hours and points have already been returned to main methd, right?Yes, but then the main method ignores them.
    So, they should be available at this point in the code, is that right?Available in the sense that you can read them, but not in the sense that there are hours and points variables within scope in the main method.
    You want to do this:
    public static void main(String[] args) {
       idNum();
       float hours = crHours();
       float points = nbrpoints();
       //create a new float
       float myComputetdGpa = grPtAvg(hours, points);
       System.out.println("Student's GPA is " + myComputedGpa);
    }

  • Javac compiler Error - cannot resolve symbol - symbol  StringBuilder?

    Hi ,
    I am using hp - ux system with java version "1.4.2.06". when i try to compile a program called CharSequenceDemo.java which is found in the java tutorials at this link
    [CharSequenceDemo.java|http://java.sun.com/docs/books/tutorial/java/IandI/examples/CharSequenceDemo.java]
    i get the following error:
    $/opt/java1.4/bin/javac CharSequenceDemo.java
    CharSequenceDemo.java:38: cannot resolve symbol
    symbol : class StringBuilder
    location: class CharSequenceDemo
    StringBuilder sub =
    ^
    CharSequenceDemo.java:39: cannot resolve symbol
    symbol : class StringBuilder
    location: class CharSequenceDemo
    new StringBuilder(s.subSequence(fromEnd(end), fromEnd(start)));
    ^
    CharSequenceDemo.java:44: cannot resolve symbol
    symbol : class StringBuilder
    location: class CharSequenceDemo
    StringBuilder s = new StringBuilder(this.s);
    ^
    CharSequenceDemo.java:44: cannot resolve symbol
    symbol : class StringBuilder
    location: class CharSequenceDemo
    StringBuilder s = new StringBuilder(this.s);
    ^
    4 errors
    Please help on how to compile this program.

    I've been struggling with the same issue. The difference is that my system says I'm using version 1.6.0_05. I've tried running jucheck.exe. It tells me I've got the latest version installed.
    Here is the code:
    import java.lang.StringBuilder;
    import java.util.Formatter;
       public class UsingFormatter {
         public static void main(String[] args) {
           if (args.length != 1) {
             System.err.println("usage: " +
               "java format/UsingFormatter <format string>");
             System.exit(0);
           String format = args[0];
           StringBuilder stringBuilder = new StringBuilder();
           Formatter formatter = new Formatter(stringBuilder);
           formatter.format("Pi is approximately " + format +
             ", and e is about " + format, Math.PI, Math.E);
           System.out.println(stringBuilder);
       }When I type javac UsingFormatter.java, I get:
    UsingFormatter.java:1: cannot resolve symbol
    symbol : class StringBuilder
    location: package lang
    import java.lang.StringBuilder;
    ^
    UsingFormatter.java:2: cannot resolve symbol
    symbol : class Formatter
    location: package util
    import java.util.Formatter;
    ^
    UsingFormatter.java:14: cannot resolve symbol
    symbol : class StringBuilder
    location: class UsingFormatter
    StringBuilder stringBuilder = new StringBuilder();
    ^
    UsingFormatter.java:14: cannot resolve symbol
    symbol : class StringBuilder
    location: class UsingFormatter
    StringBuilder stringBuilder = new StringBuilder();
    ^
    UsingFormatter.java:15: cannot resolve symbol
    symbol : class Formatter
    location: class UsingFormatter
    Formatter formatter = new Formatter(stringBuilder);
    ^
    UsingFormatter.java:15: cannot resolve symbol
    symbol : class Formatter
    location: class UsingFormatter
    Formatter formatter = new Formatter(stringBuilder);
    ^
    6 errors
    The compiler refuses to recognize the symbols StringBuilder and Formatter.
    I have spent hours googling for an answer and trying every suggestion. Nothing works, not even the one about dropping the computer from the rooftop.
    Ultimately, what I'm trying to accomplish (in a different program) is to use a text file as a form letter template and replace the %s placeholders with stings from my form object.
    Any advice?
    Edited by: javastudent_99 on Apr 3, 2008 1:48 PM

  • Compile error - cannot resolve symbol

    Hello,
    I am trying this code although I get compile errors as stated.
    import java.util.Scanner;
    * Write a program that reads 10 numbers from the keyboard into
    * an array and then prints the list of numbers
    * Modify the above program so that it prints the numbers in reverse order
    class Keyboard
      public static void main (String[] argStrings)
         System.out.println("Enter 10 numbers please");
         Scanner scan = new Scanner(System.in);
         int[] newArray = new int[10];
         for(int i = 0; i < 10; i++)
              newArray[i] = scan.nextInt();
         System.out.println();
         for(int i = 9; i > 0; i--)
              System.out.print(newArray);
    System.out.println();
    I have googled for solutions but have had no luck or could not understand.
    Please could someone explain what is going on.
    Cheers

    E:\Documents and Settings\John\Desktop\Computing\Programming\Weeks\Week11\Keyboard.java:1: cannot resolve symbol
    symbol : class Scanner
    location: package util
    import java.util.Scanner;
    ^
    E:\Documents and Settings\John\Desktop\Computing\Programming\Weeks\Week11\Keyboard.java:15: cannot resolve symbol
    symbol : class Scanner
    location: class Keyboard
         Scanner scan = new Scanner(System.in);
    ^
    E:\Documents and Settings\John\Desktop\Computing\Programming\Weeks\Week11\Keyboard.java:15: cannot resolve symbol
    symbol : class Scanner
    location: class Keyboard
         Scanner scan = new Scanner(System.in);
    ^
    3 errors
    Tool completed with exit code 1
    cheers

  • Compiler error cannot resolve symbol

    Hi people,
    i'm having this compile time error that, when i create a class and calling that class in another class gives the error cannot resolve symbol classname and it also happened when i created a bean and referencing the bean class in another bean when i'm using Jsp. thanks in advance.

    It would be helpful if you post the exact error message. If you use a system Classpath, then it must contain the root directory for the package directory(s).
    For example, if the source code for a file starts with
    package my.package;
    and you have a directory structure c:\myjava\classes\my\package then the Classpath must contain c:\myjava\classes.

  • Code won't compile!  (cannot resolve symbol)

    I'm having trouble compiling some code. Do any of you guys know why this won't work?
    * Simulation of one die (now modified for multiple with inheritance)
    * @author Kristian Hermansen
    * @version 3/14/2004 (Section 2 honors)
    public class Experiment1 extends DiceExperiment
    // instance variables
    int numSides = 6;
    int numDice = 1;
    int lowCombo = 1;
    Object[] obj;
    int[] array;
    public Experiment1()
    obj = new Object[lowCombo];
    array = new int[(numSides * numDice) + 1];
    for(int i=0; i < obj.length; i++)
    obj[i] = new Die();
    // this constructor takes arguments for number of number of dice, die sides,
    // and number of lowest side. Trying to be as generic as possible to permit
    // inheritance. We assume that all dice are the same for this application.
    public Experiment1(int dice, int sides, int low)
    numSides = sides;
    numDice = dice;
    lowCombo = numDice * low;
    obj = new Object[lowCombo];
    array = new int[(numSides * numDice) + 1];
    for(int i=0; i < obj.length; i++)
    obj[i] = new Die();
    // throws one die 2000 times and saves all the results in an int array
    public void runExperiment()
    int tally = 0;
    for(int i=0; i < 2000; i++)
    // this puts the counter for outcome k in the array indexed by k
    for(int j=0; j < obj.length; j++)
    tally += obj[j].roll();
    array[tally]++;
    makeBarGraph(array, lowCombo);
    The problem is in this line:
    tally += obj[j].roll();
    but it should work since I have the roll() method defined in the Die() class...
    * This class simulates a 6-sided die
    * @author Kristian Hermansen
    * @version 3/14/2004 (Section 2 Honors)
    import java.util.Random;
    public class Die
    // instance variables
    private static Random generator = new Random();
    private int num;
    * Constructor for objects of class Die
    public Die()
    // initialise instance variables
    num = roll();
    * This method simulates a roll
    public int roll()
    return (generator.nextInt(6) + 1);
    public String toString()
    return num + "";

    Bizarro World Error Message Theory: Error messages, whether from the compiler or the runtime, are not your enemy. They are the friend you know will always be honest with you, even when it hurts. They're telling you something's going wrong. Don't panic. It can be fixed.
    The error message will tell you exactly what it can't recognize.

  • Stop a known compile error (Cannot resolve symbol)

    I get a known compile error is their some way to stop this.
    Basically I call a reader in a method in my main class to be used in a threaded search.
    I only reset the reader when I want to so I can search for further results without starting from the start of the file again.
    I know that there is no way for the program to get to this point without having the filereader class loaded so I want to stop this error.
    Im thinking their is probably a way of putting in an if statement around my call to the search thread to check the object is in memory.
    Thanks for the help in advance.

    I get a known compile error is their some way to stop this. Yes, fix the code so it's syntactically correct. That's the only way to get rid of compiler errors.
    Im thinking their is probably a way of putting in an
    if statement around my call to the search thread to
    check the object is in memory.This isn't C/C++ with #define and #ifdef for preprocessor directives. What are you thinking?
    Fix your code and the compiler errors will go away.
    %

  • When i try to use max() & pow() in jdbc i get error "cannot resolve symbol"

    hi,
    when i tried to use pow() & max() in my jdbc programme i got compilation error "cannot resolve symbol".
    even i have imorted java.math
    this is the sample.
    pr1= (fy/(L*B*pow(10.0,-6.0))+((6*mx)/(L*B*B*pow(10.0,-6.0)))+((6*mz)/(B*L*L*pow(10.0,-6.0))));
    all of above are double.
    and with max();
    pr=max(pr1,pr2);
    all of above are double.
    please help.
    thanks in advance.
    satish

    hi
    Hartmut
    thanks hartmut;
    i am new in java so i have some problems, but thanks for helping me.
    please help me again.
    as i have already posted another probleme which i have with selecting 1000 rows 1 by 1 from a table & manipulate 1 by 1 on that and then store all manipulated row to another table.
    when i tried to do so i am able to select only 600 rows and manipulate them & store them.
    i did not get any exception or any error.
    can this possible that microsoft access driver has not that much capacity to provide 1000 rows or it is problem with jdbc.
    please help.
    satish
    thanks again.

  • Error compiling EJB.jar  + cannot resolve symbol+while deploying

    I am getting following
    Error compiling EJB.jar , cannot resolve symbol ,Syntax error in source, am getting around 17 errors while deploying EAR generated using Jdev905 into standalone oc4jContainers(10g).
    Can anyone please help me out where is the problem.
    Regards,
    Anup

    cannot resolve symbol ,Syntax error in source
    indicates some jar file is not in the Classpath. Is j2ee.jar in the Classpath?

  • "cannot resolve symbol" when compiling a class that calls methods

    I am currently taking a Intro to Java class. This problem has my instructor baffled. If I have two classes saved in separate files, for example:
    one class might contain the constructor with get and set statements,
    the other class contains the main() method and calls the constructor.
    The first file compiles clean. When I compile the second file, I get the "cannot resolve symbol error" referring to the first class.
    If I copy both files to floppy and take them to school. I can compile and run them with no problem.
    If I copy the constructor file to the second file and delete the "public" from the class declaration of the constructor, it will compile and run at home.
    At home, I am running Windows ME. At school, Windows 2000 Professional.
    The textbook that we are using came with a CD from which I downloaded the SDK and Runtime Environment. I have tried uninstalling and reinstalling. I have also tried downloading directly from the Sun website and still the error persists.
    I came across a new twist tonight. I copied class files from the CD to my hard drive. 4 separate files. 3 of which are called by the 4th.
    I can run these with no problem.
    Any ideas, why I would have compile errors????
    Thanks!!

    Oooops ... violated....
    Well first a constructor should have the same name as the class name so in our case what we have actually created is a static method statementOfPhilosophy() in class SetUpSite and not a constructor.
    Now why does second class report unresolved symbol ???
    Look at this line
    Class XYZ=new XYZ();
    sounds familiar, well this is what is missing from your second class, since there is no object how can it call a method ...
    why the precompiled classes run is cuz they contain the right code perhaps so my suggestion to you is,
    1) Review the meaning and implementation of Constructors
    2) Ask your instructor to do the same ( no pun intended ... )
    3) Check out this for understanding PATH & CLASSPATH http://www.geocities.com/gaurav007_2000/java/
    4) Look at the "import" statement, when we have code in different files and we need to incorporate some code in another it is always a good idea to use import statement, that solves quite a few errors.
    5) Finally forgive any goof up on this reply, I have looked at source code after 12 months of hibernation post dot com doom ... so m a bit rusty... shall get better soon though :)
    warm regards and good wishes,
    Gaurav
    CW :-> Mother of all computer languages.
    I HAM ( Radio-Active )
    * OS has no significance in this error
    ** uninstalling and reinstalling ? r u nuttttttts ??? don't ever do that again unless your compiler fails to start, as long as it is giving a valid error it is working man ... all we need to do is to interpret the error and try to fix the code not the machine or compiler.

  • Problem using PixelGrabber ( cannot resolve symbol ) - newbie

    Hi All,
    I have a problem with my short program because the compiler write this (jdk1.4) :
    img.java:17: cannot resolve symbol
    symbol : constructor PixelGrabber (java.awt.Image,int,int,int,int,int[],int)
    location: class java.awt.image.PixelGrabber
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this
    ),image.getHeight(this),pixels,0);
    ^
    1 error
    ... And I wrote that in my code :
    ( all is OK, the bug is only when I uncomment the line where the PixelGrabber object
    is needed in my program ).
    Thanks if you have any idea of solution to solve this problem or a doc,
    ( I don't find the answer to my problem in http://java.sun.com/j2se/1.4/docs/api/java/awt/image/PixelGrabber.html ),
    import java.awt.*;
    import java.awt.image.*;
    import java.applet.*;
    import java.awt.image.PixelGrabber;
    public class img extends Applet {
    Image image;
    int pixels[];
    public void init() {
    image = getImage(getDocumentBase(), "rouge.jpg");
    pixels = new int[image.getWidth(this) * image.getHeight(this)];
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0);
         pg.grabPixels();
    public void paint(Graphics g) {
              String s = Integer.toString(pixels[5], 16);
              g.drawString(s, 50, 50);

    Hi,
    PixelGrabber needs one more parameter scansize (width).
    change this line;
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0);
    to:
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0, image.getWidth(this)
    );

  • Getting error message Cannot Resolve Symbol when trying to compile a class

    Hello All -
    I am getting an error message cannot resolve symbol while trying to compile a java class that calls another java class in the same package. The called class compiles fine, but the calling class generates
    the following error message:
    D:\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\cal>javac
    ConnectionPool.java
    ConnectionPool.java:158: cannot resolve symbol
    symbol : class PooledConnection
    location: class cal.ConnectionPool
    private void addConnection(PooledConnection value) {
    ^
    ConnectionPool.java:144: cannot resolve symbol
    symbol : class PooledConnection
    location: class cal.ConnectionPool
    PooledConnection pcon = new PooledConnection(con);
    ^
    ConnectionPool.java:144: cannot resolve symbol
    symbol : class PooledConnection
    location: class cal.ConnectionPool
    PooledConnection pcon = new PooledConnection(con);
    The code is listed as follows for PooledConnection.java (it compiles fine)
    package cal;
    import java.sql.*;
    public class PooledConnection {
    // Real JDBC Connection
    private Connection connection = null;
    // boolean flag used to determine if connection is in use
    private boolean inuse = false;
    // Constructor that takes the passed in JDBC Connection
    // and stores it in the connection attribute.
    public PooledConnection(Connection value) {
    if ( value != null ) {
    connection = value;
    // Returns a reference to the JDBC Connection
    public Connection getConnection() {
    // get the JDBC Connection
    return connection;
    // Set the status of the PooledConnection.
    public void setInUse(boolean value) {
    inuse = value;
    // Returns the current status of the PooledConnection.
    public boolean inUse() {
    return inuse;
    // Close the real JDBC Connection
    public void close() {
    try {
    connection.close();
    catch (SQLException sqle) {
    System.err.println(sqle.getMessage());
    Now the code for ConnectionPool.java class that gives the cannot
    resolve symbol error
    package cal;
    import java.sql.*;
    import java.util.*;
    public class ConnectionPool {
    // JDBC Driver Name
    private String driver = null;
    // URL of database
    private String url = null;
    // Initial number of connections.
    private int size = 0;
    // Username
    private String username = new String("");
    // Password
    private String password = new String("");
    // Vector of JDBC Connections
    private Vector pool = null;
    public ConnectionPool() {
    // Set the value of the JDBC Driver
    public void setDriver(String value) {
    if ( value != null ) {
    driver = value;
    // Get the value of the JDBC Driver
    public String getDriver() {
    return driver;
    // Set the URL Pointing to the Datasource
    public void setURL(String value ) {
    if ( value != null ) {
    url = value;
    // Get the URL Pointing to the Datasource
    public String getURL() {
    return url;
    // Set the initial number of connections
    public void setSize(int value) {
    if ( value > 1 ) {
    size = value;
    // Get the initial number of connections
    public int getSize() {
    return size;
    // Set the username
    public void setUsername(String value) {
    if ( value != null ) {
    username = value;
    // Get the username
    public String getUserName() {
    return username;
    // Set the password
    public void setPassword(String value) {
    if ( value != null ) {
    password = value;
    // Get the password
    public String getPassword() {
    return password;
    // Creates and returns a connection
    private Connection createConnection() throws Exception {
    Connection con = null;
    // Create a Connection
    con = DriverManager.getConnection(url,
    username, password);
    return con;
    // Initialize the pool
    public synchronized void initializePool() throws Exception {
    // Check our initial values
    if ( driver == null ) {
    throw new Exception("No Driver Name Specified!");
    if ( url == null ) {
    throw new Exception("No URL Specified!");
    if ( size < 1 ) {
    throw new Exception("Pool size is less than 1!");
    // Create the Connections
    try {
    // Load the Driver class file
    Class.forName(driver);
    // Create Connections based on the size member
    for ( int x = 0; x < size; x++ ) {
    Connection con = createConnection();
    if ( con != null ) {
    // Create a PooledConnection to encapsulate the
    // real JDBC Connection
    PooledConnection pcon = new PooledConnection(con);
    // Add the Connection to the pool.
    addConnection(pcon);
    catch (Exception e) {
    System.err.println(e.getMessage());
    throw new Exception(e.getMessage());
    // Adds the PooledConnection to the pool
    private void addConnection(PooledConnection value) {
    // If the pool is null, create a new vector
    // with the initial size of "size"
    if ( pool == null ) {
    pool = new Vector(size);
    // Add the PooledConnection Object to the vector
    pool.addElement(value);
    public synchronized void releaseConnection(Connection con) {
    // find the PooledConnection Object
    for ( int x = 0; x < pool.size(); x++ ) {
    PooledConnection pcon =
    (PooledConnection)pool.elementAt(x);
    // Check for correct Connection
    if ( pcon.getConnection() == con ) {
    System.err.println("Releasing Connection " + x);
    // Set its inuse attribute to false, which
    // releases it for use
    pcon.setInUse(false);
    break;
    // Find an available connection
    public synchronized Connection getConnection()
    throws Exception {
    PooledConnection pcon = null;
    // find a connection not in use
    for ( int x = 0; x < pool.size(); x++ ) {
    pcon = (PooledConnection)pool.elementAt(x);
    // Check to see if the Connection is in use
    if ( pcon.inUse() == false ) {
    // Mark it as in use
    pcon.setInUse(true);
    // return the JDBC Connection stored in the
    // PooledConnection object
    return pcon.getConnection();
    // Could not find a free connection,
    // create and add a new one
    try {
    // Create a new JDBC Connection
    Connection con = createConnection();
    // Create a new PooledConnection, passing it the JDBC
    // Connection
    pcon = new PooledConnection(con);
    // Mark the connection as in use
    pcon.setInUse(true);
    // Add the new PooledConnection object to the pool
    pool.addElement(pcon);
    catch (Exception e) {
    System.err.println(e.getMessage());
    throw new Exception(e.getMessage());
    // return the new Connection
    return pcon.getConnection();
    // When shutting down the pool, you need to first empty it.
    public synchronized void emptyPool() {
    // Iterate over the entire pool closing the
    // JDBC Connections.
    for ( int x = 0; x < pool.size(); x++ ) {
    System.err.println("Closing JDBC Connection " + x);
    PooledConnection pcon =
    (PooledConnection)pool.elementAt(x);
    // If the PooledConnection is not in use, close it
    if ( pcon.inUse() == false ) {
    pcon.close();
    else {
    // If it is still in use, sleep for 30 seconds and
    // force close.
    try {
    java.lang.Thread.sleep(30000);
    pcon.close();
    catch (InterruptedException ie) {
    System.err.println(ie.getMessage());
    I am using Sun JDK Version 1.3.0_02" and Apache/Tomcat 4.0. Both the calling and the called class are in the same directory.
    Any help would be greatly appreciated.
    tnx..
    addi

    Is ConnectionPool in this "cal" package as well as PooledConnection? From the directory you are compiling from it appears that it is. If it is, then you are compiling it incorrectly. To compile ConnectionPool (and PooledConnection similarly), you must change the current directory to the one that contains cal and type
    javac cal/ConnectionPool.

  • Having Problem with using JUnit...causes "cannot resolve symbol" problems..

    Hello, say i have a class
    A
    that contains an object of class B.
    Now there's class X...
    It's all fine and dandy trying to compile them both until i try to set the classpath for junit, by doing:
    set classpath=%classpath%;C:\junit3.8.1\junit.jar
    i'm pretty sure it's correct...
    well once i type in this line into my command prompt (win 2k), the junit package now seems to be recognized by class X, which is my testing class that contains an object of class A.
    but NOW class A can't find class B and i get a cannot resolve symbol error. Same goes for class X not being able to find class A.
    Anyone have any suggestions? I'm a newb to this :( . Thanks.

    nevermind! noob mistake.

Maybe you are looking for

  • My ipod touch will not charge, turn on, or appear in itunes, what can i do?

    My ipod touch will not charge, turn on, or appear in itunes, what can i do? When i plug it in to my compuer it shows an empty battery with the charge symbol then after a while it shows the apple logo like it is turning on then nothing happens and it

  • ISE 1.2 EAP-TLS handshake to external RADIUS

    Hi everyone! I'm trying to implement ISE to authenticate a wireless network using a cisco WLC 5508, I have an ISE virtual Appliance version 1.2  and a WLC 5508 version 7.6 with several 3602e Access Points (20 aproximately). Right now they are authent

  • Custom authentication in WL 8.1

    I have a web app that uses BASIC authentication. What I want is for the standard web app login box to be used, but then I want to use a custom database table to verify the username password. How do I do this in weblogic 8.1.

  • Cache control in wml

    hi, I am getting problem in cache controlling in wml page for example a image displayed on the page is not displaying again but i am getting same in the console..help me out....

  • Reg. repository

    Hi, Currently i have database 9.2.0.1.0 on windows with Forms 10g release 2. I want to use the Oracle Designer. For that i have to built repository. I have read that there are seperate repositories for designer and database. I want to know why reposi