DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Struts problem

  1. #1
    Join Date
    Nov 2004

    Talking Struts problem

    Hi everyone,
    could anyone help me with a proble in connecting a database through struts. Im using tomcat 4.1 and Eclipse IDE. well the IDE is not relevant but ...I have created a connection class in which i Have the following code :

    public class MyConnection
    public Connection con=null;
    public ResultSet rs=null;
    public PreparedStatement ps=null;
    private DataSource ds=null;

    private DataSource GetDataSource()
    throws NamingException
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/temp");
    return ds;
    catch(NamingException ex)
    throw new NamingException("Naming look up Failue first time" + ex.getMessage());
    catch(Exception ex)
    throw new NamingException("Naming look up Failue in initialization." + ex.getMessage());

    Now How do i add a <context> code into server.xml. Im connecting to a sybase database. When i careate an object of the above code in a program and call it, it gives the following error :
    Error in initializing connection Naming look up Failue first time Cannot create resource instance

    I just want to know what code is to be added to the server.xml of tomcat.

    following is the driver name and the URL for connectivity

    con = DriverManager.getConnection("jdbc:sybase:Tds:","sa","");

    pls help as soon as you can,
    thanks a lot,
    your answer will be a great help to me.
    Awaiting replies,

  2. #2
    Join Date
    Aug 2004
    On the net
    Hi Saroj,

    Its good to see you back . I'll put down the info I know related to your question. Check it out if it is of any use. I'm unaware of entries in server.xml as I configured the datasource through Eclipse IDE .I'll put into steps the way I configured my app .

    1. In Eclipse, I opened the server configuration and created a datasource in the datasource tab and configured the datasource to my database by specifying all the required info there.

    2. Later, I defined a properties file and I read the url and I searched in a context just as you did.
    "DataSource ds = ...."

    3. For retrieving the connection, I used the "ds" object and retrieved the connection as
    "<connection object>=ds.getConnection(<username>,<password>)" and used connection object accordingly.

    Give a try in this way.

    Good Luck,
    Narayana :-)

  3. #3
    Join Date
    Apr 2004

    Talking Remember, Google is out friend

    Hope this helps


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center