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