Help! use DataSource in Tomcat

I configure server.xml and web.xml in tomcat to use DataSource
server.xml is
<Resource name="jdbc/jsptest" auth="Container"
               type="javax.sql.DataSource"/>
               <ResourceParams name="jdbc/jsptest">                    
<parameter><name>user</name><value>aa</value></parameter>
<parameter><name>password</name><value>aa</value></parameter>
<parameter><name>driverClassName</name>
<value>sun.jdbc.odbc.JdbcOdbcDriver</value></parameter>
<parameter><name>driverName</name>
<value>jdbc:odbc:ejbtest</value></parameter>
</ResourceParams>
and the web.xml is
<web-app>
<resource-ref>
<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>
<res-ref-name>jdbc/jsptest</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Sharable</res-sharing-scope>
</resource-ref>
</web-app>
but ,when I run my jsp ,it always throws
TyrexDataSourceFactory: Cannot create DataSource, Exception
java.lang.ClassNotFoundException: org.hsql.jdbcDriver
I didn't use org.hsql.jdbcDriver ,so I change other jdbc Drivers and receive same
result,why?
Thank everyone ,it drives me crazy!

Dear kbpv43a
here iam facing the same problem as "ClassNotFoundException: org.hsql.JDBCDriver" even after iam using thin driver for oracle database. i already commented as i dont know where i missed to close
the /> end tag. but still its throwing the same exception.
can u please help me by just going through my program and suggest me
where i committed mistake..??
here are my server.xml,web.xml and servletApplication for gettting conection from the pool using thin driver for oracle using Tomcat4.0.4
version.
thanx.
server.xml
<Server port="8005" shutdown="SHUTDOWN" debug="0">
          <!-- Tomcat Stand-Alone Service -->
<Service name="Tomcat-Standalone">
     <!-- Non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector className="org.apache.catalina.connector.http.HttpConnector"
port="8080" minProcessors="5" maxProcessors="75"
enableLookups="true" redirectPort="8443"
acceptCount="10" debug="0" connectionTimeout="60000"/>
          <!-- AJP 1.3 Connector on port 8009 -->
<Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
port="8009" minProcessors="5" maxProcessors="75"
acceptCount="10" debug="0"/>
          <!-- Top level container in our container hierarchy -->
<Engine name="Standalone" defaultHost="localhost" debug="0">
     <!-- Global logger unless overridden at lower levels -->
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="catalina_log." suffix=".txt"
timestamp="true"/>
     <!-- Because this Realm is here, an instance will be shared globally
          <Realm className="org.apache.catalina.realm.MemoryRealm" /> -->
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
          driverName="oracle.jdbc.driver.OracleDriver"
               connectionURL="jdbc:oracle:thin:@oracle:1521:ORCL"
connectionName = "mail"
connectionPassword = "mail"
          userTable="users" userNameCol="user_name" userCredCol="user_pass"
               userRoleTable="user_roles" roleNameCol="role_name" />
               <!-- Define the default virtual host -->
<Host name="localhost" debug="1" appBase="webapps" unpackWARs="true">
     <Valve className="org.apache.catalina.valves.AccessLogValve"
     directory="logs" prefix="localhost_access_log." suffix=".txt"
     pattern="common"/>
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="localhost_log." suffix=".txt"
     timestamp="true"/>
               <!-- Tomcat Root Context -->
               <!-- Tomcat Manager Context -->
<Context path="/manager" docBase="manager" debug="0" privileged="true"/>
<!-- My context, username=good and password=bad for my oracle to connect -->
     <Context path="/localhost" docBase="localhost" debug="0" reloadable="false" override="true">
          <Resource name="jdbc/myConnection" auth="Container" type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/myConnection">
               <parameter><name>user</name><value>good</value></parameter>
               <parameter><name>password</name><value>bad</value></parameter>
               <parameter><name>driverClassName</name><value>oracle.jdbc.driver.OracleDriver</value></parameter>
               <parameter>
                    <name>url</name>
                    <value>jdbc:oracle:thin:@oracle:1521:ORCL</value>
               </parameter>
               <parameter>
                    <name>maxActive</name>
                    <value>32</value>
               </parameter>
               <parameter>
                    <name>maxIdle</name>
                    <value>10</value>
               </parameter>
          </ResourceParams>
<!-- end of MY Context -->
               <!-- Tomcat Examples Context
<Context path="/examples" docBase="examples" debug="0" reloadable="true" crossContext="true">
-->
<!--
<Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_examples_log." suffix=".txt" timestamp="true"/>
     <Ejb name="ejb/EmplRecord" type="Entity" home="com.wombat.empl.EmployeeRecordHome" remote="com.wombat.empl.EmployeeRecord"/>
<Environment name="maxExemptions" type="java.lang.Integer" value="15"/>
<Parameter name="context.param.name" value="context.param.value" override="false"/>
<Resource name="jdbc/EmployeeAppDb" auth="SERVLET" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/EmployeeAppDb">
<parameter><name>user</name><value>sa</value></parameter>
<parameter><name>password</name><value></value></parameter>
<parameter><name>driverClassName</name><value>org.hsql.jdbcDriver</value></parameter>
<parameter><name>driverName</name><value>jdbc:HypersonicSQL:database</value></parameter>
</ResourceParams>
<Resource name="mail/Session" auth="Container" type="javax.mail.Session"/>
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.host</name>
<value>localhost</value>
</parameter>
</ResourceParams>
-->
</Context>
</Host>
</Engine>
</Service>
     <!-- Define an Apache-Connector Service -->
<Service name="Tomcat-Apache">
<Connector className="org.apache.catalina.connector.warp.WarpConnector"
port="8008" minProcessors="5" maxProcessors="75"
enableLookups="true" appBase="webapps"
acceptCount="10" debug="0"/>
<Engine className="org.apache.catalina.connector.warp.WarpEngine"
name="Apache" debug="0">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="apache_log." suffix=".txt"
timestamp="true"/>
          <Realm className="org.apache.catalina.realm.MemoryRealm" />
</Engine>
</Service>
</Server>
web.xml
<?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/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>conServlet</servlet-name>
<servlet-class>conServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>conServlet</servlet-name>
<url-pattern> /conServlet </url-pattern>
</servlet-mapping>
<resource-ref>
<description> Resource reference to java.sql.Connection
factory defined in server.xml
</description>
<res-ref-name>jdbc/myConnection</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
Servlet Application:
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
     res.setContentType("text/html");
     PrintWriter out = res.getWriter();
//Ordinary jdbc connection      
               //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
               //con=DriverManager.getConnection("jdbc:oracle:thin:@oracle:1521:ORCL","mail","mail");
               //out.println("Your con=="+con);
try
// jdbc connection from pool
     Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:/comp/env");
DataSource ds = (DataSource)envCtx.lookup("jdbc/myConnection");
conn = ds.getConnection();
     out.println("conn : " + conn);
conn.close();
     catch (Exception e)
     out.println("conn failed : " + e);
Note: my oralce username is "good" and password is "bad"
here

Similar Messages

  • Urg Problem with using DataSources in Tomcat

    I am trying to use DataSource in Tomcat4.0
    I have a simple jsp file as shown below:=
    <html>
    <head>
    <title>DB Test using DataSource</title>
    </head>
    <body>
    <%
    foo.DBTest dbt = new foo.DBTest();
    dbt.init();
    %>
    <h2>Results</h2>
    Foo <%= dbt.getFoo() %>
    Bar <%= dbt.getBar() %>
    </body>
    </html>
    and a Servlet by the name of DBTest as shown below:-
    package foo;
    import javax.naming.*;
    import javax.sql.*;
    import java.sql.*;
    public class DBTest
    String foo = "Not Connected";
    int bar = -1;
    public void init()
    try
         System.out.println("Inside INIT of DBTest");
    Context ctx = new InitialContext();
    Context envCtx = (Context)ctx.lookup("java:comp/env");
    if(ctx == null )
    throw new Exception("Boom - No Context");
    //DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/TestDB");
    DataSource ds = (DataSource)envCtx.lookup("jdbc/TestDB");
    if (ds != null)
    Connection conn = ds.getConnection();
    if(conn != null)
    foo = "Got Connection "+conn.toString();
    Statement stmt = conn.createStatement();
    ResultSet rst = stmt.executeQuery("select id, foo, bar from testdata");
    if(rst.next())
    foo=rst.getString(2);
    bar=rst.getInt(3);
    conn.close();
    }catch(Exception e)
    e.printStackTrace();
    }//end of init
    public String getFoo() { return foo; }
    public int getBar() { return bar;}
    }//end of class
    I modified my server.xml file to include this:=
    <!-- Tomcat My DataSource Testing Context -->
    <Context path="/DBTest" docBase="C:\Program Files\Apache Tomcat 4.0\webapps\DBTest"
    debug="5" reloadable="true" crossContext="true">
    <Logger className="org.apache.catalina.logger.FileLogger"
    prefix="localhost_DBTest_log." suffix=".txt"
    timestamp="true"/>
    <Resource name="jdbc/TestDB"
    auth="Container"
    type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/TestDB">
    <parameter>
    <name>factory</name>
    <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>5</value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>2</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>10000</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value>system</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>manager</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>oracle.jdbc.OracleDriver</value>
    </parameter>
    <parameter>
    <name>url</name>
    <value>jdbc:oracle:thin:@localhost:1521:Test2</value>
    </parameter>
    </ResourceParams>
    </Context>
    <!-- Tomcat My DataSource Testing Context -->
    and my web.xml file is as shown below:=
    <?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/dtd/web-app_2_3.dtd">
    <web-app>
    <description>Oracle DataSource Test App</description>
    <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/TestDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    </web-app>
    Now when i start Tomcat and try to access the jsp page i get this error in Tomcat Console:=
    Inside INIT of DBTest
    javax.naming.NamingException: Cannot create resource instance
    at org.apache.naming.NamingContext.lookup(NamingContext.java:837)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:181)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:822)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:194)
    at foo.DBTest.init(DBTest.java:25)
    at org.apache.jsp.test$jsp._jspService(test$jsp.java:60)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
    vlet.java:202)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
    82)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
    icationFilterChain.java:247)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
    ilterChain.java:193)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
    alve.java:243)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
    .java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
    alve.java:201)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
    .java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
    2344)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
    ava:164)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
    .java:566)
    at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
    rValve.java:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
    .java:564)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
    ava:170)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
    .java:564)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
    462)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
    .java:564)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
    ve.java:163)
    at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline
    .java:566)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
    a:472)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
    at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcesso
    r.java:1011)
    at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.ja
    va:1106)
    at java.lang.Thread.run(Unknown Source)
    Why is this happening .
    I am making sure the resource name in server.xml and web.xml are the same
    Any Help highly appreciated
    Thanks
    Raj

    Hi rajess_kr,
    Looks to me like you're pretty close.
    I'm assuming that you've got the JDBC driver JAR in TOMCAT_HOME/common/lib. The JAR containing your data source factory class org.apache.commons.dbcp.BasicDataSourceFactory should be in that directory, too. Since you're using Oracle, I'd also suggest that you repackage classes12.zip as a JAR file if it's not already a JAR.
    I think the JNDI lookup string should be "java:comp/env/jdbc/TestDB".
    I've got a working example on my desktop at work, but I don't seem to have one here at home. I'll give it a look on Monday and see if I can provide more details. It looks to me like you're not very far off. - MOD

  • How can I configure ang use JNDI datasource on Tomcat 4.0.x ?

    How can I configure ang use JNDI datasource on Tomcat 4.0.x ?
    Please help me , Thanks !

    Hello ,
    You need to go through the JNDI tutorial which you can access at the sun's site. It will explain all the things you need.
    By the way all you want to use JNDI datasource is JNDI class library and some naming or directory service provider, which also you can download from sun.
    Good Luck.

  • Help me understand JDBC connections using DataSource objects

    I'm writing a simple Java server application that accepts connections from multiple clients via RMI, connects to a SQL Server 2000 database via Microsoft's SQL 2000 JDBC driver, gets some data, and returns it to the client. The server application will handle every SQL database connection. However, it must be able to establish multiple simultaneous connections, since multiple clients may connect at the same time and request data.
    Sounds like a simple multi-threaded server that utilizes a connection pool for database connectivity, right? Well, if I want to do that, I have to register a PooledDataSource object with JNDI. My server threads that are handling requests will simply grab connections out of the pool to retrieve data (presumably).
    This seems like a fairly simple server application; however, all the information and tutorials I've read on using DataSource objects for database connections rather than DriverManager.getConnection() mention XML config files, J2EE application servers, Tomcat, WebSphere, etc. I really don't want to have to deal with all that just to get connection pooling and not have to use the DriverManager.getConnection() method.
    Is there a simple way to use DataSource objects without installing a lot of extra junk on my server?

    Thanks, diazlara. Your response was exactly what I needed to know. All the information I've read prior to this suggested that I had to have a J2EE server running, and that I had to register the DataSource object with JNDI. If you ladies and gents could take a quick look at this and let me know if I'm doing it correctly, I'd appreciate it.
    As proflux suggested, I wrote a connection manager:
    import java.sql.*;
    import javax.sql.*;
    import com.microsoft.jdbcx.sqlserver.*;
    public class SQLConnectionManager {
       private static ConnectionPoolDataSource connectionPool;
       // Initialize the connection manager
       public SQLConnectionManager() {
          init();
       // Retrieve a connection from the connection pool and return it
       public static Connection getConnection() {
          Connection connection = null;
          try {
             connection = connectionPool.getPooledConnection("myUsername", "myPassword").getConnection();
          catch (SQLException ex) {
             System.err.println("A problem occurred while getting a connection from the pool.");
             ex.printStackTrace();
          return connection;
       // Initialize the datasource and connection pool
       private static void init() {
          SQLServerDataSource mds = new SQLServerDataSource();
          mds.setDescription("MS SQLServerDataSource");
          mds.setServerName("127.0.0.1");
          mds.setPortNumber(1433);
          mds.setDatabaseName("SomeTable");
          mds.setSelectMethod("cursor");
          connectionPool = (ConnectionPoolDataSource) mds;
    }As you can see, I'm hard-coding the username and password for testing purposes. I'll incorporate a login/authentication system for any production code that I use this in.
    Once the SQLConnectionManager is created, connections can be retrieved as follows:
          Connection connection = null;
          try {
             connection = SQLConnectionManager.getConnection();
             System.out.println("** Got a SQL database connection from the pool");
             DatabaseMetaData metaData = connection.getMetaData();
             ResultSet rs = metaData.getCatalogs();
             while (rs.next()) {
                System.out.println("\tcatalog: " + rs.getString(1));
             rs.close();
             connection.close();
          catch (SQLException ex) {
             System.out.println("An exception occurred while connecting to the SQL Database:");
             ex.printStackTrace();
          }So, how does that look? I tested it out, and it seems to work just fine. Using this code, I am getting a connection from a pool, correct? I want to make sure of that. Also, are there any inherent weaknesses or flaws with this method that I need to be aware of?
    Thanks so much for all the helpful responses.

  • How to configure Oracle Datasource in Tomcat

    Hello,
    My configuration of a Tomcat Datasource (oracle) appears to be wrong. Either that or my oraclejdbc.jar file is in the wrong place. Perhaps my classpath setting is wrong. Any help is appreciated.
    Tomcat console error:
    20070423 20:46:22.514 http-8080-Processor24(0x005878d2)
    JdbcUtil#getDataSourceObject() Throw com.waveset.util.ConfigurationError: Failed to load JDBC DataSource 'java:comp/env/jdbc/wrsPool':
    ==> javax.naming.OperationNotSupportedException: Can't generate an absolute name for this namespace
    Trace output from JdbcUtil:
    XPRESS exception:
    Can't call method getDataSourceObject on class com.waveset.util.JdbcUtil ==> com.waveset.util.ConfigurationError: Failed to load JDBC DataSource 'java:comp/env/jdbc/wrsPool': ==> javax.naming.OperationNotSupportedException: Can't generate an absolute name for this namespace
    XPRESS exception:
    Can't call method queryRecords on class com.waveset.util.JdbcUtil ==> java.lang.NullPointerException:
    The express code used to call JdbcUtil follows:
    <defvar name='dataSource'>
    <new class='javax.sql.DataSource'/>
    </defvar>
    <set name='dataSource'>
    <invoke name='getDataSourceObject' class='com.waveset.util.JdbcUtil'>
    <null/>
    <s>java:comp/env/jdbc/wrsPool</s>
    <null/>
    </invoke>
    </set>
    The Tomcat configuration *.xml file
    <?xml version='1.0' encoding='utf-8'?>
    <Context docBase="wavex" path="/wavex" useNaming="false" workDir="work\Catalina\localhost\wavex">
    <Resource name="jdbc/waveexPool " type="javax.sql.DataSource"/>
    <Resource name="jdbc/wrsPool" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/waveexPool ">
    <parameter>
    <name>url</name>
    <value>jdbc:sqlserver://localhost:1433;DatabaseName=WaveEx</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value></value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>4</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>5000</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value></value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>2</value>
    </parameter>
    </ResourceParams>
    <ResourceParams name="jdbc/wrsPool">
    <parameter>
    <name>url</name>
    <value>jdbc:oracle:thin:@vega.vf.lmco.com:1521:dev2</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value></value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>4</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>5000</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>oracle.jdbc.driver.OracleDriver</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value></value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>2</value>
    </parameter>
    </ResourceParams>
    </Context>
    Environment is:
    IDM 7.0 on Windows 2000, sql server houses the repository.
    Tomcat 5.0.28 with JDK 1.6

    thanks for the reply, i have configured the connection pool settings in the tomcat.
    I created a class with static method, which will return the connection object.
    whenever i need the connection object, iam invoking the static method, once its usage is over iam closing thew connection..
    is it the right way of using the connection object in the web application.

  • When is it appropriate to use DataSource (or Connection pooling)?

    Hello all,
    I'm having some design issues with my application and I'm starting to think that maybe using Connection pooling is not suited for my application. I'm using Tomcat 5.5.12 if it's any relevant..
    The architecture of our application looks like this:
    Servlets -> App Helper classes -> DB/Accessor classes
    looks like the three-tier architecture described in this document: http://www.subrahmanyam.com/articles/servlets/ServletIssues.html
    I have read on the Tomcat docs that said that using DataSource is good practice and improves efficiency since it recycles database connections. However, if the accessor/DB classes are not servlets, how can I use the DataSource facility that interacts with Tomcat?
    I would like to know whether it is a good idea to use DataSource in my case and if so, how? (since they are not servlets)
    Thanks in advance :)

    Hi. Thank you for replying.
    In the examples that I've seen that use JNDI for Database access, it seems that DataSource is always used--in other words, JNDI and DataSource always seem to be used together (in Servlets). I have not found a case where JNDI is used by itself to access the Database--perhaps I'm not looking in the right place. Could you point me to some documentation maybe?
    Thanks a lot!

  • How to use DataSource and External transaction in 9ias?

    I'm working on a project that the application server needs to connect to over 100 databases.
    I'd like to use connection pooling and external transaction service defined in OC4J's Datasources.
    I wonder if anyone has an example of using datasource and external transaction service for OC4J.
    Right now, I export toplink project to a java source and do the initialization there manually but I don't know how to use Datasource to get connections and how to use the external transaction service in the java code for OC4J.
    I really appreciate you help.
    Wei

    Here is a fill in the blank example on how you could set this up through code:
    Project project = new MyProject();
    // alternatively, use the XMLProjectReader
    server = project.createServerSession();
    server.getLogin().useExternalConnectionPooling();
    server.getLogin().setConnector(new JNDIConnector(new javax.naming.InitialContext(), "jdbc/DataSourceName"));
    // the next line depends on the type of driver you want to use.
    server.getLogin().useOracleThinJDBCDriver();
    server.getLogin().useOracle();
    server.getLogin().setUserName("username");
    server.getLogin().setPassword("password");
    server.getLogin().useExternalTransactionController();
    server.setExternalTransactionController(new Oracle9iJTSExternalTransactionController());
    server.logMessages();
    server.login();

  • Using javabean in tomcat(unable to compile class)

    Hello, I am using jakarta-tomcat-5.0.28, OS:WinXP
    I am getting the following error when i use javabean in tomcat (the example is executed just fine in another web server:Blazix)
    I am very new to this (JSP, Servlets and tomcat) so any help would be greatly appreciate.
    THE ERROR IS:
    ==============================================================
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 1 in the jsp file: /SaveName.jsp
    Generated servlet error:
    C:\Programs\internet\jakarta-tomcat-5.0.28\work\Catalina\localhost\JSPSession\org\apache\jsp\SaveName_jsp.java:42: cannot resolve symbol
    symbol : class UserData
    location: class org.apache.jsp.SaveName_jsp
    UserData user = null;
    ^
    An error occurred at line: 1 in the jsp file: /SaveName.jsp
    Generated servlet error:
    C:\Programs\internet\jakarta-tomcat-5.0.28\work\Catalina\localhost\JSPSession\org\apache\jsp\SaveName_jsp.java:44: cannot resolve symbol
    symbol : class UserData
    location: class org.apache.jsp.SaveName_jsp
    user = (UserData) jspxpage_context.getAttribute("user", PageContext.SESSION_SCOPE);
    ^
    An error occurred at line: 1 in the jsp file: /SaveName.jsp
    Generated servlet error:
    C:\Programs\internet\jakarta-tomcat-5.0.28\work\Catalina\localhost\JSPSession\org\apache\jsp\SaveName_jsp.java:46: cannot resolve symbol
    symbol : class UserData
    location: class org.apache.jsp.SaveName_jsp
    user = new UserData();
    ^
    3 errors
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
         org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
    ===============================================================
    ERROR END
    I use the folowing files:
    GetName.html
    SaveName.jsp
    NextPage.jsp
    UserData.java
    My Dir Structure is:
    /JSPSession
        GetName.html
         SaveName.jsp
         NextPage.jsp
       /WEB-INF
          /classes
             UserData.java
             UserData.class
       /libThe Code for the files is:
    GetName.html
    <HTML>
    <BODY>
    <FORM METHOD=POST ACTION="SaveName.jsp">
    What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
    What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
    What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4>
    <P><INPUT TYPE=SUBMIT>
    </FORM>
    </BODY>
    </HTML>---------------------------------------------------------------------------------------------------
    SaveName.jsp
    <jsp:useBean id="user" class="UserData" scope="session"/>
    <jsp:setProperty name="user" property="*"/>
    <HTML>
    <BODY>
    <A HREF="NextPage.jsp">Continue</A>
    </BODY>
    </HTML>-----------------------------------------------------------------------------------------------------
    NextPage.jsp
    <jsp:useBean id="user" class="UserData" scope="session"/>
    <HTML>
    <BODY>
    You entered<BR>
    Name: <%= user.getUsername() %><BR>
    Email: <%= user.getEmail() %><BR>
    Age: <%= user.getAge() %><BR>
    </BODY>
    </HTML>------------------------------------------------------------------------------------------------------------
    UserData.java
    public class UserData {
        String username;
        String email;
        int age;
        public void setUsername( String value ) {
            username = value;
        public void setEmail( String value ) {
            email = value;
        public void setAge( int value ) {
            age = value;
        public String getUsername() { return username; }
        public String getEmail() { return email; }
        public int getAge() { return age; }
    }

    A very common question. Tomcat dislikes classes which are not packaged. So, add a package statement in your UserBean.java
    package beans; // or something like thatand then place the compiled class file UserBean.class into WEB-INF/classes/beans.
    Put the import statement into the JSP accordingly and try again.
    ***Annie***

  • How to use datasources to connect to database ?

    I have the following Problem
    I have two identical databases, one is the development database, the other one the production database.
    Now I need to find a way, how I can deploy an bc4j-application in local mode that way, that if the application is deployed to server 1 it connects to database 1 and if deployed to server 2 it connects to database 2.
    JDBC connection strings do not work as the connection is deployed with the application. So the application always connects to the same database.
    I thought datasources might be the solution. So I tried to define a datasource MyDS in the data-sources.xml file and specified it in the Configuration Wizard as the connection to use.
    But unfortunately this does not work and i do not know why:
    If I try to connect using the tester and using this datasource I get the following exception:
    Level #3: javax.naming.noInitialContextException
    Can anyone help me, what this means? How can I get around this using the BC4J Framework? Is there any "HowTo" Document which describes using datasources with BC4J?

    Frank,
    I've sorted this stuff out to some extent. Have a look at this thread:
    re:? How: multiple myAppWar.ear to use OC4J's data-sources.xml pooling?
    If this isn't all you need, then search on data-source.xml
    and read other threads also I may have posted helps on
    other threads so if you search on data-source.xml and my handle (curt504) it brings up all the threads that I posted to.
    Not to say I've solved all your problems, but I solved mine anyway. :)
    Good luck,
    curt

  • Re: Using already running Tomcat server for development.

    Hi Nick,
    Yes, you can use existing Tomcat Server for debugging app developed with
    NitroX. And you can refer to Help > Help Contents > NitroX User Guide >
    NitroX Tour > Running and debugging the application.
    We do support Tomcat 4.0.x to Tomcat 5.0.x. If you need any further
    assistance please get back to us.
    Thanks
    M7 Support
    "Nick Mulder" <[email protected]> wrote in message
    news:41d9f379$[email protected]..
    Sorry if this has been covered anywhere else.Just wondering if you can use an existing tomcat server for debugging
    webapps being developed in NitroX. I have a non dedicated server a
    development server. Up until purchasing NitroX I have been using ant build
    files to compile and re-deploy my apps into the running tomcat server.
    Just wondering if I can do something similar thru NitroX and Eclipse.
    Forgive me if I am missing something obvious, but I am new to eclipse.
    Thanks,
    Nick Mulder

    Take a look at these links: http://plato.acadiau.ca/courses/comp/dsilver/2513/EclipseAndTomcatTutorial/
    http://www.keyboardsamurais.de/2004/01/15/tomcat_tutorial_helloworld_for_complete_fools_-_english/
    http://www-128.ibm.com/developerworks/opensource/library/os-ectom/?ca=dgr-lnxw16EclipsTomcat
    I've found going through tutorials is a proven, quick way of getting up to speed with new tools and configurations.
    HTH,
    James

  • Using Datasource in OC4J  to connect to 9iDb(ArrayIndexOutOfBoundsException

    Hi all,
    I've been encountering a certain ArrayIndexOutOfBoundsException when attempting to connect to Oracle 9i
    via a defined datasource.
    I've taken the following troubleshooting steps but to no avail:
    1. Verified username and password
    2. Verified URL by having a test class to establish a direct connection using this URL
    3. Verified that both classes12.jar and ocrs12.jar are defined in the classpath
    3. Updated classes12.jar and ocrs12.jar from the OTN to copies stipulated to be compliant with 9.2.0.1
    (this was based on a post on the net with reference to similar error messages:http://www.orafaq.net/msgboard/java/messages/1488.htm)
    It would be great if anyone could have some input on this problem.
    Thanks!
    WK
    My development environment:
    Oracle Database 9.2.0.1
    oc4j
    The following configuration and code snippets are provided for reference:
    data-sources.xml
         <data-source
              class="com.evermind.sql.DriverManagerDataSource"
              name="OraclePool"
              location="jdbc/OracleCoreDS"
              xa-location="jdbc/xa/OracleXADS"
              ejb-location="jdbc/OracleDS"
              connection-driver="oracle.jdbc.driver.OracleDriver"
              username="USER"
              password="PASSWORD"
              inactivity-timeout="30"
              url="jdbc:oracle:thin:@localhost:1521:OracleDb"
    />
    Client Code:
    InitialContext ic = new InitialContext();
    DataSource ds = (DataSource)ic.lookup("jdbc/OracleDS");
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    String strQuery = "SELECT id FROM TBL_PART";
    ResultSet rset = stmt.executeQuery (strQuery);
    Error:
    java.lang.ArrayIndexOutOfBoundsException
         at oracle.security.o3logon.C1.r(C1)
         at oracle.security.o3logon.C1.l(C1)
         at oracle.security.o3logon.C0.c(C0)
         at oracle.security.o3logon.O3LoginClientHelper.getEPasswd(O3LoginClientHelper)
         at oracle.jdbc.ttc7.O3log.<init>(O3log.java:290)
         at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:251)
         at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:252)
         at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:365)
         at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:260)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:118)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.DriverManagerConnectionPoolDataSource.getPooledConnection(DriverManagerConnectionPoolDataSource.java:24)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.OrionPooledDataSource.getPooledConnection(OrionPooledDataSource.java:273)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.PooledConnectionUsage.getPooledConnection(PooledConnectionUsage.java:21)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.OrionPooledDataSource.getConnection(OrionPooledDataSource.java:145)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.DriverManagerXADataSource.getAutoCommitConnection(DriverManagerXADataSource.java:226)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.LogicalDriverManagerXAConnection.intercept(LogicalDriverManagerXAConnection.java:88)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.FilterConnection.createStatement(FilterConnection.java:324)
         at com.evermind[Oracle9iAS (1.0.2.2) Containers for J2EE].sql.FilterConnection.createStatement(FilterConnection.java:325)

    Hi WK,
    According to your stack trace, you are using a very old version of OC4J. I suggest updating to the latest, production version: 9.0.3
    Also, I seem to recall reading somewhere (I think it was in this forum), that "DataSource" is not serializable, and therefore cannot be transferred to the client.
    I use "DataSource" in my BMP entity beans to interact with the database -- this works fine. I have not tried getting a "DataSource" from a remote client, though.
    And also you may need to pass some "properties" to your "InitialContext" constructor -- depending on the type of client you are using (which I could not ascertain from your post).
    Hope this has helped you.
    Good Luck,
    Avi.

  • How to improve the load performance while using Datasources for the Invoice

    HI All,
    How to improve the  load performance while using Datasources for the Invoice . Actually my invoice load (Appx. 0.4 M records) is taking very long time nearly ~16 to 18 hrs  to update data from R/3 to 0ASA_DS01.
    If I load through flat file it will load with in ~20 Min for the same amount of data.
    Please suggest how to improve load performance.
    PS: I have done the Inpo package settings as per the OSS note.
    Regads
    Srininivasarao.Namburi.

    Hi Srinivas,
    Please refer to my blog posting [/people/divyesh.jain/blog/2010/07/20/package-size-in-spend-performance-management-extraction|/people/divyesh.jain/blog/2010/07/20/package-size-in-spend-performance-management-extraction] which gives the details about the package size setting for extractors. I am sure that will be helpful in your case.
    Thanks,
    Divyesh
    Edited by: Divyesh Jain on Jul 20, 2010 8:47 PM

  • Retrieve db connection using datasource object

    The problem is: i can't retrieve the connection to database
    using datasource object in jsp.
    my jsp was build by Oracle9i Report Builder,then deployed
    to OC4J jsp container,
    i define the datasource at container level,
    but an error "log on not specified" arise.
    is it possible to use datasource object in such a way or not?
    thanks you for your help.

    What is the full Java and os versions you are using to compile and to run. Note that with JDEV the platform used for your code may be different than the platform used by JDEV itself.
    Please modify all of your exception handlers to print the stack trace. Add this as the first line in each handler.
    ex.printStackTrace();The stacktrace contains important information about where the problem really occured.
    See the Java docs for NamingException - http://docs.oracle.com/javase/6/docs/api/javax/naming/NamingException.html
    >
    This is the superclass of all exceptions thrown by operations in the Context and DirContext interfaces. The nature of the failure is described by the name of the subclass. This exception captures the information pinpointing where the operation failed, such as where resolution last proceeded to.
    •Resolved Name. Portion of name that has been resolved.
    •Resolved Object. Object to which resolution of name proceeded.
    •Remaining Name. Portion of name that has not been resolved.
    •Explanation. Detail explaining why name resolution failed.
    •Root Exception. The exception that caused this naming exception to be thrown.

  • Where can I find how to use DataSource?

    Hi,
    I am quite new to JDBC and is writing some small database program. I find many examples use DataSource, I want to know how to use it, but cannot find the API in the docs section of java.com.
    Can anyone point me to the location of javax.sql.DataSource, or even better some examples of using DataSource?
    Also, I am using Oracle as my database, do I need to register the oracle driver first for DataSource first also?
    Any help will be approcaited.

    Hi,
    You can get the more detailed documentation at
    http://java.sun.com/j2se/1.4/docs/api/javax/sql/DataSource.html and please visit http://www.datadirect-technologies.com/download/docs/jdbc/jdbcref/usejdbc.htm for information on how to connect to database using datasources.
    Hope this helps.
    With Regards
    Gayam_Slash

  • Help using jar file!

    Help using jar file!
    Hello
    I have created a jar file by using
    jar cvmf Manifest.txt myjar.jar 1.class Mydirectory
    In 1.java file :I have used
    JEditorPane editor;
    editor.setPage(getClass().getResource("/Mydirectory/default.htm"));
    If I am only giving myjar.jar file to the client without Mydirectory then also it is working fine by showing default.htm in JeditorPane.
    But my problem is I want to use
    Runtime.getRuntime().exec("cmd /c start IEXPLORE"+targetstr) ;
    targetstr will be the filename with path of the default.htm
    If I am giving myjar.jar file with Mydirectory to the client it is working but I don't want to give Mydirectory to the client .
    What should I do?
    Is there any solution for this?
    Using another jar file which will include mydirectory can solve this problem?
    Is there any othe concept in java so that I wll be able to hide Mydirectory from client?
    Please help.

    It seems like you could extract the .htm file from the jar, either with Runtime.exec or using the Jar API classes.

Maybe you are looking for