Thanks in advance. I am stuck with the problems for days:
In my web application when I am navigating to http://localhost:8080/publisher/news.rss,
I am getting the following errors:
Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
publisher.web.NewsFeedServlet.doGet(NewsFeedServle t.java:86)
javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
root cause
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
org.apache.tomcat.dbcp.dbcp.BasicDataSource.create ConnectionFactory(BasicDataSource.java:1452)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.create DataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getCon nection(BasicDataSource.java:1044)
publisher.web.NewsFeedServlet.doGet(NewsFeedServle t.java:59)
javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
root cause
java.lang.NullPointerException
sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.knownURL(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(Unknown Source)
java.sql.DriverManager.getDriver(Unknown Source)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.create ConnectionFactory(BasicDataSource.java:1437)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.create DataSource(BasicDataSource.java:1371)
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getCon nection(BasicDataSource.java:1044)
publisher.web.NewsFeedServlet.doGet(NewsFeedServle t.java:59)
javax.servlet.http.HttpServlet.service(HttpServlet .java:621)
javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.
i have done a lot of googling but nothing is working for me.
This my publisher.xml file:
<Context path="/publisher" docBase="I:\Eclispe work\publisher\WebContent">
<Resource name="datasource"
type="javax.sql.DataSource"
auth="Container"
maxActive="10"
maxIdle="3"
maxWait="10000"
username="publisher"
password="publisher"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/publisher?autoReconnect=true" />
</Context>
this NewsFeedServlet.java file:
package publisher.web;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import org.apache.log4j.*;
import com.sun.syndication.feed.synd.*;
import com.sun.syndication.io.*;
public class NewsFeedServlet extends HttpServlet {
private Logger logger = Logger.getLogger(this.getClass());
private static DataSource dataSource;
public static void setDataSource(DataSource dataSource)
{
NewsFeedServlet.dataSource=dataSource;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType("rss_2.0");
feed.setTitle("My Local News Feed");
feed.setLink("http://localhost:8080/publisher/");
feed.setPublishedDate(new Date());
feed.setDescription("This feed was created using ROME");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
try{
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("select * from news_item");
while(resultSet.next()){
String title = resultSet.getString("title");
String url = resultSet.getString("url");
Date pDate = resultSet.getDate("pubDate");
//System.out.print(pDate);
//logger.debug(pDate);
SyndEntry entry= new SyndEntryImpl();
entry.setTitle(title);
entry.setLink(url);
entry.setPublishedDate(pDate);
entries.add(entry);
}
connection.close();
} catch (SQLException e){
throw new ServletException(e);
}
resp.setContentType("text/xml");
feed.setEntries(entries);
Writer writer = resp.getWriter();
SyndFeedOutput output = new SyndFeedOutput();
try{
output.output(feed, writer);
}catch(FeedException e){
logger.error("",e);
}
}
}
and this is Init.java file:
package publisher.web;
import javax.naming.*;
import javax.servlet.*;
import javax.sql.*;
import org.apache.log4j.*;
public class Init implements ServletContextListener {
private Logger logger = Logger.getLogger(this.getClass());
private void contextInitialized2(ServletContext servletContext)
throws Exception {
InitialContext enc = new InitialContext();
Context compContext = (Context) enc.lookup("java:comp/env");
DataSource dataSource = (DataSource) compContext.lookup("datasource");
NewsFeedServlet.setDataSource(dataSource);
}
@Override
public void contextInitialized(ServletContextEvent sce) {
// TODO Auto-generated method stub
ServletContext servletContext = sce.getServletContext();
try {
contextInitialized2(servletContext);
}
catch (Exception e)
{
logger.error("Initialization failed.", e);
throw new RuntimeException(e);
}
logger.debug("Initialization succeeded.");
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// TODO Auto-generated method stub
}
}
So that's all. Please someone help me out. I dont know where is the problem and how to solve.....
Thanks in advance....