From: Mike Schilling on


"Alessio Stalla" <alessiostalla(a)gmail.com> wrote in message
news:1cab63c6-ecc7-4968-8ac2-847c79d1d1c8(a)k39g2000yqb.googlegroups.com...
> On Jun 10, 4:23 am, "Mike Schilling" <mscottschill...(a)hotmail.com>
> wrote:
>> "Alessio Stalla" <alessiosta...(a)gmail.com> wrote in message
>>
>> news:7de01547-d88d-4c26-8932-6be63d419927(a)u7g2000yqm.googlegroups.com...
>>
>> > On 9 Giu, 14:27, Lew <no...(a)lewscanon.com> wrote:
>> >> Alessio Stalla wrote:
>> >> > If I'm not mistaken, the class should be loaded because it's
>> >> > referenced in the constant pool, but it will be "initialized" only
>> >> > when you access it in some way (create an instance, access a static
>> >> > member). "Initialized" is not the correct term, by that I mean that
>> >> > static code blocks are executed and static fields are initialized.
>>
>> >> You're not mistaken and "initialized" is the correct term.
>>
>> > OK, thanks. I wasn't 100% sure and, yes - I was lazy and I didn't look
>> > it up :)
>>
>> But, terminology aside, you are mistaken. See my previous post.
>
> Right. I tried it myself, too. I suspect it's a compiler optimization
> that removes the local variable altogether because it's never used.
> Although the compiler seems pretty smart - even with
>
> B b = (1 == (0 + 1)) ? null : new B();
> if(b == null) { ... }
>
> there's no trace of B in the bytecode.

Even with A.java thus

class A
{
B b;

public static void main(String[] arrs)
{
A a = new A();
a.run();
}

public void run()
{
System.out.println("Hello, world");
}

public void method()
{
b = new B();
}

public B method2()
{
return b;
}
}

A still runs OK after B.class is removed. I don't think it's a compiler
optimization as much as it is that class loading can be done very lazily.

From: Arne Vajhøj on
On 05-06-2010 16:19, Pif - 34 wrote:
> Arne Vajh�j wrote:
>> Exact exception text?
>>
>> Listing of content of webapps/yourwebapp?
> I've replaced " Class.forName("oracle.jdbc.driver.OracleDriver"); "
> by oracle.jdbc.driver.OracleDriver oracleDriver = null;
>
> and this works perfectly. So my Jar is well placed, this seems to be an
> error with the ClassLoader of tomcat !?

Not likely.

Both Tomcat and Oracle are very widely used products.

Arne
From: Kevin McMurtrie on
In article <4c0ab15e$0$32742$426a34cc(a)news.free.fr>,
Pif - 34 <fj(a)nospam.fr> wrote:

> I've replaced " Class.forName("oracle.jdbc.driver.OracleDriver"); "
> by oracle.jdbc.driver.OracleDriver oracleDriver = null;
>
> and this works perfectly. So my Jar is well placed, this seems to be an
> error with the ClassLoader of tomcat !?
>
> Arne Vajh�j wrote:
>
> > Exact exception text?
> >
> > Listing of content of webapps/yourwebapp?
> >
> > Arne

Are you compiling against one version of the driver but running with a
different? I could be wrong, but I think
'oracle.jdbc.driver.OracleDriver' is sometimes a private class. Try
'oracle.jdbc.OracleDriver'.
--
I won't see Google Groups replies because I must filter them as spam
From: Lew on
Pif - 34 wrote:
>> I've replaced " Class.forName("oracle.jdbc.driver.OracleDriver"); "
>> by oracle.jdbc.driver.OracleDriver oracleDriver = null;
>> and this works perfectly.

As pointed out upthread, this does not. Something else must "work", whatever
"work" means to you, Pif, but of course, you refuse to show us any code so we
really cannot tell.

>> So my Jar [sic] is well placed, [sic] this seems to be an
>> error with the ClassLoader of tomcat [sic] !? [sic]

Tchyaah, right!

Kevin McMurtrie wrote:
> Are you compiling against one version of the driver but running with a
> different? I could be wrong, but I think
> 'oracle.jdbc.driver.OracleDriver' is sometimes a private class. Try
> 'oracle.jdbc.OracleDriver'.

I believe that 'oracle.jdbc.driver.OracleDriver' is public in all the JARs
Oracle distributes, but that's moot anyway. Plus I could be wrong also.

Using the 'DriverManager' way to load the driver, you are supposed to use
'oracle.jdbc.OracleDriver' in preference to the other as you say. However,
that whole technique, according to Oracle, and to Sun even before Oracle
acquired it, is deprecated.

<http://download.oracle.com/docs/cd/E11882_01/appdev.112/e12137/getconn.htm#CACCCIIC>
"Note:
"The use of the DriverManager class to establish a connection to a database is
deprecated."

They tell you to use 'oracle.jdbc.pool.OracleDataSource' instead.

I go a tad further and suggest following Tomcat's instructions on how to set
up a data source.

However, "Pif - 34" has shown no interest in Arne's or my suggestions,
responding to our questions or providing an SSCCE, so I suppose I'm just
shouting in the wilderness.

Come to think of it, we haven't heard from "Pif" at all in over a week. I
hope they're all right!

--
Lew