The mysteries of JDBC, JNDI, and Tomcat 5.5.4

Like thousands beforefore, I can't get connection pooling to work in Tomcat. I followed all the steps:
- put jar file for MySQL JDBC driver in TOMCAT_HOME/common/lib
- put the Jakarta Commons libs in the same location
- put resource declaration in META-INF/context.xml, per the Tomcat 5.5 docs like so:
<Context docbase="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\commutercorps"
    path="\commutercorps" >
    <Resource name="jdbc/commutercorpsds"
</Context>- added resource ref in web.xml
        <description>DB Connection</description>
    </resource-ref>I also double checked my connection URL and found that it does work fine when do this in my Java code:
Connection con =
    ("jdbc:mysql://localhost:3306/commuter_corps_signup", "...", "...");When I try to use Tomcat 5.5.4, JNDI like this...
                    InitialContext initialContext = new InitialContext();
                    DataSource dataSource =
                            (DataSource) initialContext.lookup
                    Connection con = dataSource.getConnection();
                    Statement stmt = con.createStatement();
                } catch (NamingException e)
                }...I get...
Cannot create JDBC driver of class '' for connect URL 'null'
Caused by: java.sql.SQLException: No suitable driver
Any help would be greatly appreciated.

I used to get the message
Cannot create JDBC driver of class '' for
connect URL 'null'
No suitable driverError.
I was running, jakarta-tomcat-5.0.14.exe on windows.
I had it installed on a path without spaces
I wanted to use Hibernate. So i used, extensiontools.What's that?
First create a env var: HIBERNATE_HOME pointing to
the hibernate extracted dir.No need for this.
Modify setenv.bat to correct %CP% for
commons-logging, commons-collection and anything
else: the version string at the end of the jar
changes.Wrong. You shouldn't be doing this.
Then run ddl2hbm, straightforward, fill info in all
tabs and hit generate. Will show some error message,
but still creates xmls.I don't see what any of this has to do with Tomcat deployment.
Then run hbm2java, and hand over each xml file as
parameter. Creates some java files in generated dir.
Modify the toString method to something simpler and
remove the import for apache class.All great, but still has nothing to do with Tomcat deployment.
move them over to webapp classes.You should create a WAR file or a separate context directory for your application under /webapps. If you're doing anything else, it's wrong.
Create JNDI in sever.xml as mentioned.Nope. Shouldn't be editing server.xml. Put that stuff in an application-specific context.xml, which goes in the META-INF of your WAR file.
Create reference in web.xml as mentioned.Good.
Goto conf/catalina/localhost/<webappname>.xmlNo need for this. Don't know what you're doing here.
add the line
<ResourceLink name="jdbc/Oracle"
type="javax.sql.DataSource" global="jdbc/Oracle"/>
replace Oracle with your datasource name.
and i got me workingMight be working, but it's not really correct.

Similar Messages

  • JNDI and Tomcat

    Alright. I'm new using JNDI, but i get all the Context, Binding, lookup operations and rellated issues.
    But, I need to connect to a server who has Tomcat using JNDI. (A high-school homework)
    In a manner of fact, I need to create 2 subcontext an in the last one I need to bind a name with a reference to cmd.exe (it seems that I need to execute it), all of it using Tomcat's JNDI connection capabilities.
    but when I'm trying to Construct the Initial Context reference, I'm not doing it in the right way... this is my Hashtable:
    Hashtable env = new Hastable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, //I don't know what the hell goes hereApparentntly from web examples I have seen, It's the Implementation of the JNDI SPI from the Service Provider I want to connect... I really don't know which one to put when using Tomcat, or find other one.
    I read in the HOW-TO section in the apache site, but find nothing...
    or didn't get the idea, I saw they only get the container like this:
    Context ct = new InitialContext();
    with no arguments... but I also tryed to do it that way, but the same NamingException is thrown, with the message that I need to psecify the context factory. Well. I hope it's clear my trouble, and any of you would help me.
    Not reporting anything else. Thanks.

    have you check the following link
    Tomcat 5 provides a JNDI InitialContext implementation instance to web applications running under it, in a manner that is compatible with those provided by a Java2 Enterprise Edition application server. Entries in this InitialContext are configured in the $CATALINA_HOME/conf/server.xml file, and may be referenced by the following elements in the web application deployment descriptor (/WEB-INF/web.xml) of your web application:
    used the resource file <resource-env-ref> , do not harcdode your
    basic data source factory
    and bean factory

  • JDBC(JNDI):Connection dinamically managed

    Hi all,
    I'm using
    1) Crystal Reports 2008 for the reports' design,
    2) Java Reporting Component (version for the integration in java environment,
    3) JBoss (version 4.2.3) as Application Server
    4) Oracle 11 as DBMS
    in a web application.
    When I create a report using JDBC (JNDI) and specify as the "Connection Name (optional)" the following string "java:jdbc/name_data_source",
    How is managed the connection of the report and any sottoreports? In other words are the connections dynamically managed by the container web or ejb?
    Thank you very much.

    Hi, Andrea,
    I'm gonna' make a few guesses here:
    2) Java Reporting Component (version
    I think you mean Crystal Reports for Java (CRJ) 2.8 version Neither the JRC (the name for the 1.x series) nor the CRJ (the 2.x series) has any version number in the 18.x range.
    I think that means "subreports."
    are the connections dynamically managed by the container web or ejb?
    There are two ways the connections can be managed. If you've created a JNDI connection (a named connection), then you can base a report off of it, then at a later date change where the JNDI connection itself points to and the report should still work correctly, as long as the new target database shares the same schema as the original.
    The other way you can manage the connection is to use code to change the database connection information inside the report itself. In this way, you could change it from one JNDI connection to another or even to another type of connection altogether. Again, however, the schemas between the old and the new connections must match.

  • Problem loading jdbc driver in Tomcat

    I have got a connection to MySQL5.0 from TomCat 5.5.13, that was test correctly in development (JSC Upd 1) but I encounter the following deployment error :
    com.sun.rave.web.ui.appbase.ApplicationException: org.apache.jasper.JasperException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
    When I verify, I found that if I put the mysql Connector JDBC driver in <tomcat>/common/lib, there is no error.
    But when the MySql Connector JDBC driver resides in <tomcat>/shared/lib, the error persists.
    What's the difference ? shouldn't it work for both ?
    Thanks in advance for any pointers and advise.

    hmm... i guess that it's a must to include the lib at /common/lib instead of shared/lib .
    Is there a Tomcat resource that I can read up on ?

  • JDBC thin and thick clients

    What is the difference between JDBC thin and JDBC thick clients and their usage ?

    in sort tearms,
    Oracle has a thin client driver which mean you can connect to a oracle database without the Oracle client installed on your machine.
    Thick client would need the Oracle Client database drivers etc.. Drivers include JDBC-ODBC bridge drivers JDBC drivers depending on tns resolution.

  • How to Install and Configure Java and Tomcat

    Hi Everybody,
    I am using the following versions of java and tomcat:
    JAVA: j2sdk-1_4_2_13
    Tomcat: jakarta-tomcat-5.0.5
    I tried to configure several times both but everytime the result is the same. I am setting the following variables:
    PATH: .;D:\j2sdk1.4.2_13\bin;D:\Tomcat 5.0\bin
    CLASSPATH: .;D:\j2sdk1.4.2_13\lib;D:\Tomcat 5.0\common\lib\servlet-api.jar
    JAVA_HOME: D:\j2sdk1.4.2_13
    Please correct what mistake i am doing again and again. I appreciate your effort.
    Thanks in advance.

    Fine sir, I will tell evrything in detail what steps i am following during installation and configuring java and Tomcat.
    1) I am using the following versions(exe) of java and tomcat:
    JAVA: j2sdk-1_4_2_13-windows-i586-p
    Tomcat: jakarta-tomcat-5.0.5
    2) Then, i follow exactly the same variable names and values to configure java as mentioned below to make java work under User variables header:
    PATH: .;D:\j2sdk1.4.2_13\bin
    CLASSPATH: .;D:\j2sdk1.4.2_13\lib
    JAVA_HOME: D:\j2sdk1.4.2_13
    Above steps i follow only for installing java. And it also not working properly. If i run my .java file from the destination of the file then it will be execulted but if i try to execute from any other location then it doesn't, it shows the following message in the DOS prompt:
    error: cannot read:
    1 error
    Now, please correct what mistake i am doing.

  • Directory Editor and Tomcat

    Hey all,
    I am installing Directory Editor 6.0, and following the install documentation, I added some lines to the 'catalina.policy' file in the Tomcat configuration to allow DE to work properly.
    grant codeBase "file:${catalina.home}/webapps/de/-" {
    grant codeBase "file:${catalina.home}/webapps/de/-" {
      permission "getLoginConfiguration";
      permission "setLoginConfiguration";
      permission "createLoginContext.SunDirectoryLogin";
      permission "modifyPrincipals";
      permission java.util.PropertyPermission "*", "read,write";
      permission "*", "connect,resolve";
      permission "*", "read, write";
      permission java.util.PropertyPermission "Debug.enable", "read";
    grant {
      permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
      permission java.lang.RuntimePermission "accessClassInPackage.sun.beans.*";
      permission java.lang.RuntimePermission "";
      permission java.lang.RuntimePermission "accessDeclaredMembers";
    };I deployed the WAR file, and was able to perform the initial configuration of DE (location of the config directory, what suffix to configure, what credentials to connect to the DS as...). Once those steps finish, I can see data in the DS under the newly created "Services" OU for DE, but when I try to login to DE as either a regular user or as an administrative user, I get an error. The catalina.out log show the following:
    2007-06-25 16:00:14,398 [TP-Processor11] WARN  org.apache.struts.action.RequestProcessor - Unhandled Exception thrown: class java.lang.SecurityException
    2007-06-25 16:00:14,398 [TP-Processor11] ERROR com.sun.dml.web.DmlRequestProcessor - No exception handler for java.lang.SecurityException: Unable to locate a login configuration.  Forwarding to error page.
    java.lang.SecurityException: Unable to locate a login configuration
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
            at java.lang.reflect.Constructor.newInstance(
            at java.lang.Class.newInstance0(
            at java.lang.Class.newInstance(
            at Method)
            at com.sun.dml.web.LoginAction.execute(
            at org.apache.struts.action.RequestProcessor.processActionPerform(
            at com.sun.dml.web.DmlRequestProcessor.processActionPerform(
            at org.apache.struts.action.RequestProcessor.process(
            at org.apache.struts.action.ActionServlet.process(
            at org.apache.struts.action.ActionServlet.doPost(
            at javax.servlet.http.HttpServlet.service(
            at javax.servlet.http.HttpServlet.service(
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(
            at org.apache.catalina.core.StandardWrapperValve.invoke(
            at org.apache.catalina.core.StandardContextValve.invoke(
            at org.apache.catalina.core.StandardHostValve.invoke(
            at org.apache.catalina.valves.ErrorReportValve.invoke(
            at org.apache.catalina.core.StandardEngineValve.invoke(
            at org.apache.catalina.connector.CoyoteAdapter.service(
            at org.apache.jk.server.JkCoyoteHandler.invoke(
            at org.apache.jk.common.HandlerRequest.invoke(
            at org.apache.jk.common.ChannelSocket.invoke(
            at org.apache.jk.common.ChannelSocket.processConnection(
            at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(
            at org.apache.tomcat.util.threads.ThreadPool$
    Caused by: Unable to locate a login configuration
            ... 32 moreIs there anything else that needs to be done to allow access for DE when using Tomcat?
    TIA, Mark

    here is the info re: Directory Editor and Tomcat 5.5:
    When deploying on Tomcat 5.5, login fails due to a missing JAAS configuration file
    To work around this issue, first create tomcat-install-path/bin/ containing the following line:
    Next create tomcat-install-path/conf/jaas.conf. Edit the file to contain the following lines:
    SunDirectoryLogin {
    com.sun.dml.auth.SunDirectoryLoginModule required;

  • Difference between Tomcat4.X and Tomcat 5.X ?

    Can any body tell me what is the difference between Tomcat4.X and Tomcat 5.X ?

    corlettk wrote:
    difference between Tomcat4.X and Tomcat 5.X ? 1for a given value of 1.

  • Problem with JNDI and JSP in Tomcat

    Basically, what I've done is to use the Tomcat administration web
    application to create the DataSource, which looks like it populated the
    server.xml (see below). I then try to access the testconn.jsp, and am
    getting that "Name java:comp is not bound in this Context" error.
    I was wondering if anyone could tell me what I'm doing wrong?
    My Configuration:
    - Tomcat 5.0.19
    - MySQL 4.0.18-nt
    - mysql-connector-java-3.0.15-ga-bin.jar
    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    <!-- Editable user database that can also be used by
    UserDatabaseRealm to authenticate users -->
    <Resource name="UserDatabase" auth="Container"
    description="User database that can be updated and saved">
    <ResourceParams name="UserDatabase">
    <!--Feri test JNDI-->
         <Context crossContext="true" debug="5" docBase="injury" path="/injury" reloadable="true">
         <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_injury_log." suffix=".txt" timestamp="true"/>
              <Resource name="jdbc/injury" auth="Container"
    <ResourceParams name="jdbc/injury">
    <!--Feri test JNDI end-->
    <description>Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file.</description>
    <%@ page import="java.sql.*" %>
    <%@ page import="javax.sql.*" %>
    <%@ taglib prefix="ct" uri="/injury" %>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
    <h1>Connection test</h1>
    <ct:connection name="jdbc/injury">
    Statement stmt= conn.createStatement();
    ResultSet rs;
    rs = stmt.executeQuery("select * from user");
    while ({
    %><%=rs.getString(1)%><%=rs.getInt(2) %><br><%
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    import javax.naming.*;
    import javax.sql.*;
    import javax.sql.DataSource;
    public class ConnectionTag extends TagSupport implements TryCatchFinally {
    private Connection conn;
    // JNDI name of the connection
    private String name;
    public void setName(String name) = name;
    public int doStartTag()
         throws JspException
         try {
         Context env = (Context) new InitialContext().lookup("java:comp/env");
         DataSource ds = (DataSource) env.lookup(name);
         if (ds != null)
              conn = ds.getConnection();
         } catch (Exception e) {
         throw new JspException(e);
         if (conn == null)
         throw new JspException("can't open connection " + name);
         pageContext.setAttribute("conn", conn);
         return EVAL_BODY_INCLUDE;
    public void doCatch(Throwable t)
         throws Throwable
         throw t;
    public void doFinally()
         try {
         Connection conn = this.conn;
         this.conn = null;
         } catch (Exception e) {
    Tomcat 5.0\conf\Catalina\localhost\injury.xml
    <?xml version='1.0' encoding='utf-8'?>
    <Context displayName="Injury" docBase="E:\Tomcat 5.0\webapps\injury" path="/injury" className="org.apache.catalina.core.StandardContext"
    cachingAllowed="true" charsetMapperClass="org.apache.catalina .util.CharsetMapper" cookies="true" crossContext="false" debug="0"
    mapperClass="org.apache.catalina.core.StandardContextMapper" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper" >
    <Resource auth="Container" description="Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file." name="jdbc/injury" type="javax.sql.DataSource"/>
    <ResourceLink global="jdbc/injury" name="injury" type="javax.sql.DataSource"/>

    First of all, you can find alot of information about this in the forum about jsp's.
    I think a good thing to do is not to put your context tag directly into the server.xml file.
    What you should do is create a context.xml file with the context-tag in it, and put it in the META-INF directory of your .war file. Upon deployment to tomcat5 this file will be extracted from the war, copied to the conf\enginename\hostname directory, and it will be renamed to contextName.xml.
    I think you are developing directly into the webapps directory, and I believe you should avoid that and use the deployment feature of the manager web-app or you should use the deployertool from you ide or standalone ant.
    anyway, for starters try to remove the context tag from the server.xml file as described above, and check out the jsp / jdbc forums for simular problems and answers.
    good luck

  • JNDI, Data Source and Tomcat

    I am using Tomcat 4.1
    I am using JDBC to connect to to SQL 2000.
    In the past I use JDBC 2.0 standsrd package to connect to it and it was fine.
    Now, for some reason, I need to use DataSource via JNDI.
    Here is my server.xml
    <Resource name="jdbc/SQLNorthwind" scope="Shareable" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/SQLNorthwind">
    <value>select * from Products</value>
    <name>url</name> <value>jdbc:microsoft:sqlserver://W2KSERVER1:1433;DatabaseName=Northwind</value>
    It was generated by the Tomcat admin tools via the web browser.
    It is my web.xml
    Now here is my servlet source code for connection testing
    private Connection conn;
    private Statement stmt;
    private ResultSet rs;
    public void init(ServletConfig config) throws ServletException {
    try {
    Context ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("jdbc/SQLNorthwind");
    conn = ds.getConnection("george", "george");
    } catch(NamingException e) {
    this.log("Naming exception in JNDIDatabase init", e);
    } catch(SQLException e) {
    this.log("SQL exception in JNDIDatabase init", e);
    The problem is no connection is obtained in init(). So what's wrong with my setting/code? Please help me to fix my setting/code.
    Thank you in advance.

    Follow what you said, no more NamingException. Thanks, Dave.
    now I receive another error.....
    2002-10-18 00:34:12 JNDIDatabase: SQL exception in JNDIDatabase init
    java.sql.SQLException: Cannot load JDBC driver class ''
         at org.apache.commons.dbcp.BasicDataSource.createDataSource(
         at org.apache.commons.dbcp.BasicDataSource.getConnection(
         at org.apache.catalina.core.StandardWrapper.loadServlet(
         at org.apache.catalina.core.StandardWrapper.allocate(
         at org.apache.catalina.core.StandardWrapperValve.invoke(
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(
         at org.apache.catalina.core.StandardPipeline.invoke(
         at org.apache.catalina.core.ContainerBase.invoke(
         at org.apache.catalina.core.StandardContextValve.invoke(
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(
         at org.apache.catalina.core.StandardPipeline.invoke(
         at org.apache.catalina.core.ContainerBase.invoke(
         at org.apache.catalina.core.StandardContext.invoke(
         at org.apache.catalina.core.StandardHostValve.invoke(
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(
         at org.apache.catalina.valves.ErrorReportValve.invoke(
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(
         at org.apache.catalina.core.StandardPipeline.invoke(
         at org.apache.catalina.core.ContainerBase.invoke(
         at org.apache.catalina.core.StandardEngineValve.invoke(
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(
         at org.apache.catalina.core.StandardPipeline.invoke(
         at org.apache.catalina.core.ContainerBase.invoke(
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(
         at org.apache.coyote.http11.Http11Processor.process(
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(
         at org.apache.tomcat.util.threads.ThreadPool$
    I am sure msutil.jar, mssqlserver.jar and msbase.jar are stored in /WEB-INF/lib directory and using them in standard JDBC is OK!
    This is an extraction from MS JDBC help file.....
    The data source class for the SQL Server driver is:
    For information on SQL Server 2000 Driver for JDBC data sources, see "Connecting Through Data Sources".
    The driver class for the SQL Server driver is: is working properly, I am sure.

  • JNLP and Tomcat JNDI DataSource

    JDK 1.5 Update 6
    Tomcat 5.5.4
    I have a Client Side requirement and this project is going to be deployed to 5 users initially all in a lan but there are very chances of adding more users simultaneously.
    I am thinking of deploying in JNLP Environment.
    At present the Swing application though in development phase is running a little slow and therefore I required the way by which I could store the references of the Object in some server.Getting Connection Object is also a major time consumer and so I needed some way by which I can use the Tomcat DataSource and use the JNDI facility to store certain intermediate values in the server.
    Can I use the JNDI in the JNLP Application.
    Please provide me the way by which I can do this stuff
    Thanks in advance

    .> I am using tomcat 5.5.9 and oracle 9i. I am hosting a
    portal which uses connection pooling.
    I have decided to use the connection pooling through
    tomcat's JNDI naming lookup.Excellent idea.
    for this i have used the following steps --
    1) made entry of <resource-ref> in webapp's web.xml
    2) made relevant and corresponding entry in tomcat's
    ${TOMCAT_HOME}/conf/context.xml (for JNDI
    JDBC-datasource)No, don't do it that way.
    .> my problems are--
    1) making the entry for context.xml in tomcats
    conf folder makes the application war dependent
    on web server which i dont want to make.Yes, it does.
    2) i have to put classes12.jar in tomcats
    ${TOMCAT_HOME}/common/lib folder and only then the
    application connection pooling works else the
    exception coming on tomcat console is --
    Why aren't you using the latest JDBC driver from Oracle? That's in ojdbc14.jar.
    .> I dont want to put classes12.jar in web server i want
    the web server's JNDI lookup to pick the driver frm
    my webapps' internal lib folder. please help me on
    these very pressing and immediate issues. all the
    help coming from anyone in this regard is very much
    thanks in advance!
    VaivYour instinct is correct.
    (1) Put ojdbc14.jar in WEB-INF/lib of your WAR file.
    (2) Edit the <Context> XML into a file named context.xml and put it in META-INF of your WAR. Tomcat should pick up the context information for the JNDI data source from that.
    Everything is in the WAR, and you don't have any dependence on the server that way.

  • Problem with JDBC and Tomcat

    I don't know where the problem originate, the only thing in my memory is that the program worked very well on my PC yesterday, but today, without even slightest change, it doesn't work anymore. As to debug it, I simplified the codes to the least, but it still refuse to work. I was beaten down by this problem totally, and cannot make out any solution for it, so, I come here, hoping to find a warrior to kill this damned bug for me.
    My program is a Servlet, but for the purpose of debugging, I have recode it to an Application/Servlet. When run as a application, I can get the result expected, but as a Servlet, :-(, maybe you should see it by yourself. My server software is Tomcat 4.1.15, and the JDK version is 1.4.0. To excute this program, you should add Data Source "Test" to ODBC.
    ///////////////////////code begins/////////////////////////
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    public class Ex extends HttpServlet
         int ErrorType = 0;
         String err = new String("");
         public static void main(String args[]) throws Exception{
              Ex cEx = new Ex();
         public void init() {
              String url = "jdbc:odbc:Test";
              ErrorType = 3;     //passed
              } catch (ClassNotFoundException e) {
                   ErrorType = 1; //trapped in Class.forName
                   Connection c = DriverManager.getConnection(url);
              } catch (SQLException e) {
                   ErrorType = 2; //trapped in DriverManager.getConnection
                   err = e.getMessage();
         public void service(HttpServletRequest req, HttpServletResponse res)
                   throws IOException {
              res.setContentType("text/html; charset=GB2312");
              PrintWriter out = res.getWriter();
              out.println("Success " + "<p>" + ErrorType + "<p>" +err);
    //////////////////////////code ends///////////////////////////////
    The result from the Servlet tell me that the problem occurred within the connection process, I don't know who should be responsible to this - Tomcat or JDBC?

    If you could print the exception that you got then that would help :) In the mean time, I could make a guess. It is unlikely that your application server (in this case, Tomcat) is blocking connections from your servlet. So the problem is either with JDBC directly or with the underlying datasource. It seems unlikely that it is JDBC given that you have stated that the code has not changed and it works in application form.
    My guess would be that you are coming up against some sort of security constraint (eg: your DBMS is letting you log in from one IP but not another?, your Java plug-in security policy is disallowing the connection?). It's hard to say.
    But if it works as an application but not via a servlet then you could try putting this in your java.policy file, which is located in the directory where your plug-ins are installed (eg: "C:\Program Files\Java\<version>\lib\security\") on Windows systems;
    permission "bend xp:1099", "listen,connect,accept";
    Try that, see if it works :)

  • Java and Tomcat: Why do I need the port number when accessing Tomcat?

    My ultimate goal is to setup a website that displays data from a database. I will use Java, Apache, Oracle, and whatever else I need to create a website the uses servlets, JavaServer Pages, and JDBC.
    I�ve got four Pentium III computers:
    1. Windows 2000 Server to be the web server (MyWebServer, IP =
    2. Windows 2000 Professional to be the database server (MyDatabaseServer, IP =
    3. Windows 2000 Professional that I use to develop and test (MyDeveloperPC, IP =
    4. Windows 2000 Professional that I use as a client to connect to the website (MyClientPC, IP =
    I installed Java Web Services Developer Pack on MyWebServer. It requires Java 2 Standard Edition (J2SE), so I installed that first. The files I downloaded and installed are as follows:
    J2SE: j2sdk-1_4_0-rc-win.exe
    JWSDP: jwsdp-1_0-ea1-win.exe
    After installing these products, I set the environment variables as follows:
    JAVA_HOME = c:\j2se
    JWSDP_HOME = c:\jwsdp
    Path = c:\j2se\bin;c:\jwsdp\bin; [and other previous statements]
    On MyWebServer I start Tomcat (from the JWSDP menu option). It starts properly (as far as I can tell).
    Then, from MyClientPC I open Internet Explorer and in the address box I type:
    �The page cannot be displayed�.
    I then try again and add the port number:
    This displays the page c:\jwsdp\webapps\root\index.html.
    Here�s my question: Why do I have to enter the port number to get a page displayed? Do I have to have Apache HTTP Server running on MyWebServer to display pages without entering the port number?
    Thanks for your help.

    When you web server is running at the default Http Port, then you do not have to specify the port yourself.(The browser does it automatically)
    So if you run your web server at port 80, then you will not have to specify the port explicitlyin the url.
    If you want to use tomcat only as a jsp/servlet processing engine then install a web server (either IIS, or apache web server) and run it on port 80. (so that you dont have to specify the port)
    Now configure tomcat to run as a servlet engine for this web server. for this refer to the tomcat documentation.
    If you do not want to have an external webserver then you can configure tomcat itself to run at port 80 (in this case tomcat would do the work of both the web server as well as jsp/servlet engine... but this is not the setup for a production site). this can be done by changing the server.xml file in the conf directory of tomcat installation.
    hope this helps.

  • Problem using JDBC (JNDI) DataSource and data-sources.xml w/ OC4J

    I have a JClient application developed in JDev X. It works fine when using a JDBC URL for the connection (which then writes the connection into the BC4J.xcfg files, one for each application module). However, I would like the app to retrieve the data source from the server's data-sources.xml file. However, when, on the configurations tab of the application module I set the connection type to JDBC DataSource, and give it the JNDI name, it does not work, either with the embedded OC4J or the stand-alone OC4J. Any suggestions???
    In the stand alone OC4J I verified that the data source exists (using java -jar admin.jar ormi://nemethzoltan3 admin welcome -application adatklinika -testDataSource -location jdbc/adatklinikaCoreDS) ... so the data source is defined in the data-sources.xml. Of course the error I get is JBO-30003.
    If I just try to "test" the data source in Jdeveloper (using the context menu of the app module, and setting it to use the adatklinikaCoreDS) I get a JNDI error: unable to lookup data source and at level 3 a "javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial". I checked, the data source is defined under tools->embedded OC4J properties->data sources.
    If I try to run the main form, simply nothing happens.
    Please help!!!

    Ok, figured out why running from jdeveloper wasn't working: the embedded OC4J server wasn't started (start it by running an html page from your project or something...and make sure you don't have a stand-alone oc4j running). AND more importantly it didn't have the library "embedded oc4j client" library included (project properties -> profiles -> development -> libraries)...which is needed for whatever reason.
    Now to try and get it working with the stand-alone OC4J...

  • Error while retriving the connection uisng JNDI and DATASOURCE

    hi guys,
    i had a specifed data source in the the data-sources.xml of CONFIG folder of my application
    <data-source class="oracle.jdbc.pool.OracleConnectionCacheImpl"
    connection-driver="oracle.jdbc.driver.OracleDriver" location="jdbc/OracleDS_native"
    Here is the program i had written to retrive the datasource
    package javaapplication1;
    import javax.naming.InitialContext;
    import java.sql.*;
    import javax.naming.Context;
    import javax.sql.DataSource;
    public class Main {
    public Main() {
    public static void main(String[] args) {
    Connection con =null;
    try {
    InitialContext context = new InitialContext();
    DataSource ds = (DataSource)context.lookup("jdbc/OracleDS_native");
    con = ds.getConnection();
    catch( Exception exception ) {
    // process exception
    try{ con.close(); }
    catch(SQLException e)
    { e.printStackTrace();}
    ##########context********[email protected]
    javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(
    at javax.naming.InitialContext.getDefaultInitCtx(
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(
    at javax.naming.InitialContext.lookup(
    at javaapplication1.Main.main(
    what might be the problem??

    From the contents of your "data-sources.xml" file that you posted, it looks like you are using a pre-10.1.3.x version of OC4J (stand-alone?), so Jason's link may not be helpful.
    Nonetheless, as Jason mentions, you do need to set some properties that need to be passed to the "InitialContext" class constructor. Probably something like the following.
    [Note that the code is uncompiled and untested.]
    Properties prp = new Properties();
    prp.put(Context.PROVIDER_URL, "ormi://oc4j_host");
    prp.put(Context.SECURITY_PRINCIPAL, "user");
    prp.put(Context.SECURITY_CREDENTIALS, "password");
    Context ctx = new InitialContext(prp);
    DataSource ds = (DataSource) context.lookup("jdbc/OracleDS_native");And replace "oc4j_host" with the name of your OC4J host machine as well as "user" and "password" with the appropriate values.
    Note that you can probably use the OC4J admin user's details.
    Good Luck,

Maybe you are looking for

  • ACS On-demand Full Backup failed.

    Hi, I have ACS Primary Secondary Authenticators , of which the Scheduled backup has stopped. When checked the : Monitoring Configuration > System Operations > Data Management > Removal and Backup > Incremental Backup , it had changed to OFF

  • Why does the Q10 an OLED display...​.

    why does the Q10 an OLED display? there is not a long time after a problem with the color?

  • Iwork '08 on a G3 Ibook

    Can this be done. I need to make a presentation on Wednesday. The presentation was done in Keynote '08. The school was supposed to have a powerbook for me to use but they do not. Can I use my old G3 Ibook that is collecting dust? Thanks


    Hi, We're running SRM 5.5(level4) and NW2004s. We're wanting to create backend reservations under certain conditions. To do this, I've activated BADIs BBP_TARGET_OBJECTS and BBP_EXTLOCALPO_BADI. We've followed the instructions outlined in note 891924

  • OTN FTP Soooo Slow

    I'm trying to DL JDeveloper 3.1 for evaluation, but the FTP site is so slow... Does Oracle have any mirror sites? I appreciate being given access to these tools for evaluation as a developer, but think it reflects poorly on Oracle that the fastest DL