Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Tomcat JDBC setup: DataSource invalid: "java.lang.NullPointerException"

Thread view: 
cwang66@gmail.com - 11 Oct 2005 02:31 GMT
Hi,

I am trying to configure JDBC connecting to MS SQL 2000 in Tomcat
5.5.9. I have tried using JDBC drivers from both Microsoft and JTDS. I
copied JDBC jar files to [Tomcat_home]shared\lib" in both cases.
However, I am getting the following error message from both cases( I am
using JSTL in my JSP page.):

javax.servlet.jsp.JspException: Unable to get connection, DataSource
invalid: "java.lang.NullPointerException"
    org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:276)
    org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:159)
    org.apache.taglibs.standard.tag.el.sql.QueryTag.doStartTag(QueryTag.java:85)
    org.apache.jsp.userReport_jsp._jspx_meth_sql_query_0(org.apache.jsp.userReport_jsp:307)
    org.apache.jsp.userReport_jsp._jspx_meth_c_when_0(org.apache.jsp.userReport_jsp:241)
    org.apache.jsp.userReport_jsp._jspx_meth_c_choose_0(org.apache.jsp.userReport_jsp:203)
    org.apache.jsp.userReport_jsp._jspService(org.apache.jsp.userReport_jsp:120)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Below is my web.xml configuration when using JTDS driver:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
<web-app>
    <context-param>

        <param-name>
                net.sourceforge.jtds.jdbcx.JtdsDataSource
        </param-name>
        <param-value>
            jdbc:jtds:sqlserver://127.0.0.1:1433/testdb;user=xxx;password=xxx
        </param-value>

    </context-param>

</web-app>

Below is my web.xml configuration when using MS driver:

<!DOCTYPE web-app
 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
<web-app>
    <context-param>

<context-param>
 <param-name>com.microsoft.jdbc.sqlserver.SQLServerDriver</param-name>

<param-alue>jdbc:microsoft:sqlserver://localhost:1433;User=xxx;Password=xxx;DatabaseName=testdb</param-value>

</context-param>

    </context-param>
   

</web-app>

Any help is appreciated.
Manish Pandit - 12 Oct 2005 00:06 GMT
Try putting the jar files in your webapp's WEB-INF/lib folder as well.

I had this problem too, and ended up using Apache DBCP instead of
having a JNDI datasource via tomcat.

-cheers,
Manish
Roedy Green - 12 Oct 2005 00:42 GMT
>/localhost:1433;

do you have localhost defined in your hosts file?

See http://mindprod.com/jgloss/hosts.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

cwang66@gmail.com - 12 Oct 2005 02:09 GMT
The hosts file is setup by default to have the localhost setup in it. I
forgot to mention that I did get JDBC to work with mySQL (so I am
guessing maybe it's naming convention I use for M$ SQL is wrong.). I
am getting the same error message in another machine with the same
setup.

I will look into using DBCP as another solution. The frustrating part
of this small coding project is that the error message is really not
very meaningful for debugging purpose. Is there any way to configure
JSTL to spit out more verbose error message?

Thanks,
Roedy Green - 12 Oct 2005 02:51 GMT
>I will look into using DBCP as another solution. The frustrating part
>of this small coding project is that the error message is really not
>very meaningful for debugging purpose. Is there any way to configure
>JSTL to spit out more verbose error message?

I notice a higher and higher proportion of questions are about
configuring.  Nobody can help unless they are familiar with that
particular program.

What we need is something akin to
http://mindprod.com/jgloss/runerrormessages.html

Where every time you make a mistake and figure out what you did wrong,
you log the error message and the cause.   That would give others who
come after you, and yourself later encountering a similar problem a
hint.

The catch is I am not the one to do this.  I am not using all these
different tools. Further I find the syntax of these configuration
files nauseating.  And I go apoplectic reading the worse than useless
documentation on how to set them up. I want nothing to do with them.

Perhaps some masochist needs to write a book called
"How to configure"

a cookbook about configuring various popular tools, and the various
tricks for getting your files to work even when the manuals read like
Greek.

It might even come with a program on CD that asks you questions and
produces the configuration files.  It had better be a JAWS app since
it would be out of date before it hit the shelves.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Anonymous - 12 Oct 2005 19:11 GMT
Someone replied to my same question in JTDS forum in sourceforge.net.
He indicated that Tomcat DataSource configuration had changed since
5.5.  I am going to read the document through and see if I can
configure it to work:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html
Anonymous - 14 Oct 2005 01:45 GMT
> Someone replied to my same question in JTDS forum in sourceforge.net.
> He indicated that Tomcat DataSource configuration had changed since
> 5.5.  I am going to read the document through and see if I can
> configure it to work:
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html

OK, I got it to work using DBCP and JTDS driver.
Roedy Green - 13 Oct 2005 05:28 GMT
>I notice a higher and higher proportion of questions are about
>configuring.  Nobody can help unless they are familiar with that
>particular program.

for my proposed solution to this problem, see
http://mindprod.com/projects/configurator.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.