Ill paste some code below. but in short you can do a couple things.

1) look it up in the global namespace
2) look it up in the web apps namespace.

if you deploy it all, then use a web browser to go to http://yourserver:8082
you will see a JNDIView area. click on that, then find the "list" button and
click it to see your JNDI namespaces. That is where you can see what the DS
is bound to.

Here is my code to do lookups, and the appropriate entries in the jboss.jcml
file.


sql = "select distinct user_t.username, download_t.download_date," +
      "download_t.download_type from user_t, download_t where " +
        "user_t.user_pk = download_t.user_fk order by download_t.download_type
desc";

try {
        InitialContext ctx = new InitialContext();
      DataSource ds = (DataSource)ctx.lookup("java:/pagescreamerDS");
      Connection con = ds.getConnection();
      PreparedStatement ps = con.prepareStatement(sql);

      ResultSet rs = ps.executeQuery();

      while(rs.next()) {
          site    = rs.getString(1);
          date    = rs.getDate(2).toString();
          version = rs.getString(3);
        }
}
catch(Exception e) {
        . . .
}

here is my jboss.jcml entry for this DS


  <mbean code="org.jboss.jdbc.XADataSourceLoader"
name="DefaultDomain:service=XADataSource,name=OracleDB">
    <attribute name="PoolName">pagescreamerDS</attribute>
    <attribute
name="DataSourceClass">org.opentools.minerva.jdbc.xa.wrapper.XADataSourceImp
l</attribute>
    <attribute name="Properties"></attribute>
    <attribute name="URL">jdbc:oracle:thin:@localhost:1521:pgs</attribute>
    <attribute name="GCMinIdleTime">1200000</attribute>
    <attribute name="JDBCUser">user</attribute>
    <attribute name="MaxSize">10</attribute>
    <attribute name="Password">password</attribute>
    <attribute name="GCEnabled">false</attribute>
    <attribute name="InvalidateOnError">false</attribute>
    <attribute name="TimestampUsed">false</attribute>
    <attribute name="Blocking">true</attribute>
    <attribute name="GCInterval">120000</attribute>
    <attribute name="IdleTimeout">1800000</attribute>
    <attribute name="IdleTimeoutEnabled">false</attribute>
    <attribute name="LoggingEnabled">false</attribute>
    <attribute name="MaxIdleTimeoutPercent">1.0</attribute>
    <attribute name="MinSize">0</attribute>
  </mbean>


This will bind the DS to java:/pagescreamerDS which you should see on
startup. You could also bind it in your deployment descriptor in a
resource-ref entry.

The you should be able to look it up with
java:comp/env/resource-ref-name-in-deployment-descriptor.

I think the main problem here is that under BEA you were used to copying the
servlet into the classpath, and not deploying it as a web application,
whereas in jboss(with embedded tomcat or jetty) you deploy a web application
or an enterprise archive. its not as simple as just copying a servlet class,
unless you deploy the whole web app un-jarred.

Al




-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Edward Wang
Sent: Monday, June 11, 2001 9:46 PM
To: [EMAIL PROTECTED]
Subject: Re: [JBoss-user] Lookup Datasource from Javabeans. Possible?


How can you access DataSource from a servlet? I tried but only got a
"NameNotFoundException". I listed all the JNDI names within the Context, it
didn't contains
the JNDI name of my DataSource I saw that JBoss bound it to at the startup,
like "java:/oraceDS".

Did you do just as those who deploy any servlet in an WAR then in an EAR? I
used Weblogic before for more than one year, and I found, and you will find
too, it's really very convenient in this case of matters. You should code as
you like, in Servlet, in JSP, or even in an Application, then just run it,
for a servlet/jsp, you need only copy the compiled .class file to the
"SERVLET_CLASSES" directory. Then you got it! I use JBoss just because it's
free. For our customer need a cheap one than weblogic, it's too expensive!
But I never imagined JBoss is so frustrating...



----- Original Message -----
From: "Allen Fogleson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, June 09, 2001 1:10 AM
Subject: RE: [JBoss-user] Lookup Datasource from Javabeans. Possible?


> Hmm I have no problem accessing the DataSource from a servlet, or JSP.
There
> is at least one good reason to do this, taking advantage of connection
> pooling without having to write your own pool. Someone else reccommended
> against it (if i interpreted correctly) but I see no reason to NOT use the
> DataSource. This is what making the application portable is about. imagine
> that i have to do the traditional
>
> class.forName(driver).newInstance();
> DriverManager......
>
> EVERY time I want to go to the DB? then if the DB changes I now have to
> change all that code. Even with a properties file this is more painful
than
> simply change the DataSource definition once. (Admittedly there should be
at
> most 2 changes using a properties file method.) but 6 months down the road
> when someone else is doing the maintenance of your code will they remember
> to make the change?
>
> Al
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Edward Wang
> Sent: Friday, June 08, 2001 4:15 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [JBoss-user] Lookup Datasource from Javabeans. Possible?
>
>
> If the JBoss/Tomcat pack even doesn't allow my servlet to access
Datasource,
> then why would I use JBoss but not JRun or something else?
> For that, I have to write an EJB for every little piece of SQL I want to
> execute in my DB in my servlet. Is that too inconvient?
>
> ----- Original Message -----
> From: "Guy Rouillier" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, June 08, 2001 2:16 PM
> Subject: Re: [JBoss-user] Lookup Datasource from Javabeans. Possible?
>
>
> See numerous messages in the archives on this subject.  The connection
pool
> is meant to be used by EJBs running within JBoss, not by external clients.
> Won't work - connections are set up within a JVM context, and your
external
> client is in another JVM.
>
> I don't know if there is some hack to make this work with the integrated
> packages (JBoss+Tomcat or JBoss+Jetty), but even if you can you shouldn't.
>
> ----- Original Message -----
> From: "Edward Wang" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, June 07, 2001 9:44 PM
> Subject: Re: [JBoss-user] Lookup Datasource from Javabeans. Possible?
>
>
> > Seems impossible. When I was trying to connect to a Datasource that I
saw
> was bound to java:/instantDB by JBoss at the startup in my servlet.
> > But the following error was reported:
> >
> > Connection error:javax.naming.NameNotFoundException: InstandDB not bound
> >
> > Does this mean that?
> >
> > Edward
> >
> > ----- Original Message -----
> > From: "Dexter Legaspi" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Thursday, June 07, 2001 9:57 PM
> > Subject: Re: [JBoss-user] Lookup Datasource from Javabeans. Possible?
> >
> >
> > >
> > > yes!
> > >
> > > --- Tim Yates <[EMAIL PROTECTED]> wrote:
> > > > Is it possible to lookup the Datasource from my
> > > > JavaBeans?
> > > >
> > > > I use direct SQL to improve performance in several
> > > > methods, and wondered if
> > > > I could use the connection pool from my BMP beans...
> > > >
> > > > Cheers.
> > > >
> > > > Tim.
> > > >
> > > >
> > > > _______________________________________________
> > > > JBoss-user mailing list
> > > > [EMAIL PROTECTED]
> > > >
> > > http://lists.sourceforge.net/lists/listinfo/jboss-user
> > >
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Get personalized email addresses from Yahoo! Mail - only $35
> > > a year!  http://personal.mail.yahoo.com/
> > >
> > > _______________________________________________
> > > JBoss-user mailing list
> > > [EMAIL PROTECTED]
> > > http://lists.sourceforge.net/lists/listinfo/jboss-user
> > >
> > $--$~z?y-S
>
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
>
> $--$~z?ib,y+޷b?-+-Sw6ˬ
>
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
>
$,f)+-$,X(~zwib,y+޷b?+-w6ˬ


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to