Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: problem witch Apache

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post problem witch Apache

    heloo,

    I try to compile my web application. I have called "webappliction". the web application should work with PostgreSQL DBMS. I use the connection pool here is the file:

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package data;

    /**
    *
    * @author appolino
    */
    import java.sql.*;
    import javax.sql.DataSource;
    import javax.naming.InitialContext;


    public class ConnectionPool {

    private static ConnectionPool pool = null;
    private static DataSource dataSource=null;

    private ConnectionPool()
    {

    try
    {
    InitialContext ic= new InitialContext();
    dataSource = (DataSource)
    ic.lookup("java:/comp/env/jdbc/pflanze");
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }

    }

    public static ConnectionPool getInstance()
    {
    if( pool == null)
    {
    pool = new ConnectionPool();
    }

    return pool;
    }

    public Connection getConnection()
    {
    try
    {
    return dataSource.getConnection();

    }
    catch(SQLException sqle)
    {
    sqle.printStackTrace();
    return null;

    }
    }

    public void freeConnection(Connection c)
    {
    try
    {
    c.close();
    }
    catch(SQLException sqle)
    {
    sqle.printStackTrace();
    }

    }

    }


    I edited the context.xml file like follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <Context antiJARLocking="true" path="/jspbeispiel">
    <Resource auth="Container"
    driver.ClassName="org.postgresql.Driver"
    logAbandoned="true"
    maxActiv="100" maxIdle="30"
    maxWait="10000"
    name="/jdbc/pflanze"
    password="sesame"
    removedAbandoned="true"
    removedAbandonedTimeout="60"
    type="javax.sql.Datasource" url="jdbc:postgresql://locahost/Pflanze"
    username="sesameuser"/>
    </Context>


    in the attribute name = "jdbc / mydbjdbc" context.xml file I do not know really what represents "jdbc" and "mydbjdbc".does "jdbc" a directory?


    the content of file web.xml look like:

    <servlet>
    <servlet-name>eingabe</servlet-name>
    <servlet-class>servlet.eingabe</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>eingabe</servlet-name>
    <url-pattern>/eingabe</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>
    30
    </session-timeout>
    </session-config>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>



    compiling, I receive a java.lang.NullPointerException tomcat log:

    Servlet.service() for servlet eingabe threw exception
    java.lang.NullPointerException
    at data.ConnectionPool.getConnection(ConnectionPool.j ava:52)
    at data.UserDB.inssert(UserDB.java:19)
    at servlet.eingabe.processRequest(eingabe.java:56)
    at servlet.eingabe.doPost(eingabe.java:157)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11AprProcessor.proces s(Http11AprProcessor.java:877)
    at org.apache.coyote.http11.Http11AprProtocol$Http11C onnectionHandler.process(Http11AprProtocol.java:59 4)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run( AprEndpoint.java:1675)
    at java.lang.Thread.run(Thread.java:662)

    and from tomcat: I
    Reloading Context with name [/jspbeispiel] has started
    javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.ResourceFactory.getObjec tInstance(ResourceFactory.java:143)
    at javax.naming.spi.NamingManager.getObjectInstance(N amingManager.java:304)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:793)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:140)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:781)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:140)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:781)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:140)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:781)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:153)
    at org.apache.naming.SelectorContext.lookup(SelectorC ontext.java:152)
    at javax.naming.InitialContext.lookup(InitialContext. java:392)
    at data.ConnectionPool.<init>(ConnectionPool.java:28)
    at data.ConnectionPool.getInstance(ConnectionPool.jav a:42)
    at data.UserDB.inssert(UserDB.java:18)
    at servlet.eingabe.processRequest(eingabe.java:56)
    at servlet.eingabe.doPost(eingabe.java:157)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11AprProcessor.proces s(Http11AprProcessor.java:877)
    at org.apache.coyote.http11.Http11AprProtocol$Http11C onnectionHandler.process(Http11AprProtocol.java:59 4)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run( AprEndpoint.java:1675)
    at java.lang.Thread.run(Thread.java:662)

    the Error see like server can not find the Datasource


  2. #2
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: problem witch Apache

    Your context.xml is a bit messed up. Start with the PostgreSQL Tomcat JNDI docs. I configure my datasources at the virtual host level - you may or may not want to do that. My context is defined in $TOMCAT_HOME/conf/Catalina/localhost and is named ROOT.xml - this means that it is applicable to the entire virtual host. It looks like:

    <?xml version='1.0' encoding='utf-8'?>
     
    <Context path="">
      <Resource name="jdbc/something" auth="container" type="javax.sql.DataSource"
                   maxActive="100" maxIdle="10"
                   username="user" password="pass" driverClassName="org.postgresql.Driver"
                   url="jdbc:postgresql://localhost/dbname"/>
    </Context>
    Need Java help? Check out the HotJoe Java Help forums!

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem witch Apache

    thank, ich have used the doc. now my context.xml look like:
    <Context>

    <Resource name="jdbc/postgres" auth="Container"
    type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
    url="jdbc:postgresql://127.0.0.1:5432/mydb"
    username="myuser" password="mypasswd" maxActive="20" maxIdle="10"
    maxWait="-1"/>
    </Context>

    I try to compile and I have received Error: Cannot create resource instance

    29.05.2012 20:14:42 org.apache.catalina.core.StandardWrapperValve invoke
    SCHWERWIEGEND: Servlet.service() for servlet eingabe threw exception
    javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.ResourceFactory.getObjec tInstance(ResourceFactory.java:143)
    at javax.naming.spi.NamingManager.getObjectInstance(N amingManager.java:304)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:793)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:140)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:781)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:153)
    at data.ConnectionPool.<init>(ConnectionPool.java:32)
    at data.ConnectionPool.getInstance(ConnectionPool.jav a:44)
    at data.UserDB.inssert(UserDB.java:18)
    at servlet.eingabe.processRequest(eingabe.java:56)
    at servlet.eingabe.doPost(eingabe.java:157)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11AprProcessor.proces s(Http11AprProcessor.java:877)
    at org.apache.coyote.http11.Http11AprProtocol$Http11C onnectionHandler.process(Http11AprProtocol.java:59 4)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run( AprEndpoint.java:1675)
    at java.lang.Thread.run(Thread.java:662)

    the postgresql driver ist already in tomcat_home/lib

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem witch Apache

    the first error in the programm code point to this row: dataSource = (DataSource) ic.lookup("jdbc/pflanze");
    and the next point to the row: pool = new ConnectionPool();

  5. #5
    Member
    Join Date
    Apr 2012
    Location
    Superior, CO, USA
    Posts
    80
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default Re: problem witch Apache

    I used an example that I had and have attached a very small webapp that has a context.xml and uses a PostgreSQL db via a JNDI lookup. It includes an ant build file. See if this can help.

    As a side note - I can't upload a jar (to a Java forum - damn PHP programmers) so this is a zip. Create a directory under $TOMCAT_HOME/webapps. This was developed under Tomcat 7 so you may need to fix web.xml for a lower servlet spec. Unzip the attachment contents to that directory.
    Attached Files Attached Files
    Need Java help? Check out the HotJoe Java Help forums!

  6. #6
    Junior Member
    Join Date
    May 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Re: problem witch Apache

    [QUOTE=stdunbar;67437]I used an example that I had and have attached a very small webapp that has a context.xml and uses a PostgreSQL db via a JNDI lookup. It includes an ant build file. See if this can help.

    thank , for your help. I have used your example but the error message persist:
    tomcat 6

    30.05.2012 13:23:58 org.apache.catalina.core.StandardWrapperValve invoke
    SCHWERWIEGEND: Servlet.service() for servlet eingabe threw exception
    javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.factory.ResourceFactory.getObjec tInstance(ResourceFactory.java:143)
    at javax.naming.spi.NamingManager.getObjectInstance(N amingManager.java:304)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:793)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:140)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:781)
    at org.apache.naming.NamingContext.lookup(NamingConte xt.java:153)
    at data.ConnectionPool.<init>(ConnectionPool.java:32)
    at data.ConnectionPool.getInstance(ConnectionPool.jav a:44)
    at data.UserDB.inssert(UserDB.java:18)
    at servlet.eingabe.processRequest(eingabe.java:56)
    at servlet.eingabe.doPost(eingabe.java:157)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11AprProcessor.proces s(Http11AprProcessor.java:877)
    at org.apache.coyote.http11.Http11AprProtocol$Http11C onnectionHandler.process(Http11AprProtocol.java:59 4)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run( AprEndpoint.java:1675)
    at java.lang.Thread.run(Thread.java:662)

    the error see like : jndi cannot create a instance for datasource

  7. #7
    Junior Member
    Join Date
    May 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem witch Apache

    When I created a directory in tmcat_Home / webapps, where I place all my codes file, tomcat reference this error message:

    undeploy?path=/WebApp
    OK - Undeployed application at context path /WebApp
    In-place deployment at C:\tomcat\webapps\myweb\WebApp\build\web
    Deployment is in progress...
    deploy?config=file%3A%2FC%3A%2FUsers%2Fappolino%2F AppData%2FLocal%2FTemp%2Fcontext884487583192365311 2.xml&path=/WebApp
    FAIL - Deployed application at context path /WebApp but context failed to start
    C:\tomcat\webapps\myweb\WebApp\nbproject\build-impl.xml:686: The module has not been deployed.
    BUILD FAILED (total time: 0 seconds)

    Tomcat cannot deploye the module

  8. #8
    Junior Member
    Join Date
    May 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: problem witch Apache

    but when the source files in directory other than tmcat_Home / webapps, tomcat deployed without problem but can not create a instance for datasource

Similar Threads

  1. Apache XML-RPC server creation problem
    By r0x in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 10th, 2011, 09:52 AM
  2. Problem with apache xml-rpc lib
    By tah_206207 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2011, 02:31 PM
  3. Apache server restsrting problem
    By Gaurav Gupta in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 13th, 2011, 05:50 AM
  4. Need Hellp!! problem with org.apache.struts.actions.DownloadAction.copy
    By nikshri in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 6th, 2010, 01:06 AM
  5. Problem running Apache tomcat 6.0 using i.p. address
    By nakul in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: April 8th, 2010, 07:58 AM

Tags for this Thread