Обсуждение: JDBC Connectivity..

Поиск
Список
Период
Сортировка

JDBC Connectivity..

От
Minal
Дата:
I am noting down the steps..which I performed during installation and
for using JDBC....
1. DO we have to use ./configure with-java ?
because when I use that I get error that it failed. Is this the reason I
am not able to eshtablish the connectivity...
In  O'reily book it is mentioned that we have to build the driver...How
does one do that??
I have copied the postgresql driver in /usr/local/tomcat/common/lib
directory..
also set the class path...restarted the tomcat and used the java file as
shown below...

public class Example1
> >>{
> >>public static void main(String[] argv)
> >>{
> >>    System.out.println("Checking if Driver is registerd");
> >>    try
> >>    {
> >>    Class.forName("org.postgresql.Driver");
> >>    }
> >>    catch(ClassNotFoundException cnfe)
> >>    {
> >>    System.out.println("Couldn't find the Driver");
> >>    cnfe.printStackTrace();
> >>    System.exit(1);
> >>    }
> >>    System.out.println("registered the Driver OK, so lets make a
> >>connection");
> >>    Connection c = null;
> >>
> >>    try
> >>    {
> >>    c=
> >>DriverManager.getConnection("jdbc:postgresql://localhost/trainneedcorp","postgres","admin");
> >>    }
> >>    catch(SQLException se)
> >>    {
> >>    System.out.println("Couldnt connect");
> >>    se.printStackTrace();
> >>    System.exit(1);
> >>    }
> >>    if(c != null)
> >>    System.out.println("WE CONNECTED");
> >>    else
> >>    System.out.println("Reaching here is not done");
> >>    }
> >>    }

> >>    I get the following error:
> >>
> >>java.lang.ClassNotFoundException: org.postgresql.Driver
> >>        at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
> >>        at java.security.AccessController.doPrivileged(Native Method)
> >>        at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
> >>        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
> >>        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
> >>        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
> >>        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
> >>        at java.lang.Class.forName0(Native Method)
> >>        at java.lang.Class.forName(Class.java

Am I going wrong anywhere??

Re: JDBC Connectivity..

От
luke@chipcity.com.au
Дата:
Hi,

20Jun2005 @ 11:58 Minal thusly spake
> I am noting down the steps..which I performed during installation and
> for using JDBC....
> 1. DO we have to use ./configure with-java ?
> because when I use that I get error that it failed. Is this the reason I
> am not able to eshtablish the connectivity...
> In  O'reily book it is mentioned that we have to build the driver...How
> does one do that??
> I have copied the postgresql driver in /usr/local/tomcat/common/lib
> directory..
> also set the class path...restarted the tomcat and used the java file as
> shown below...

java can't find the driver,
what postgresql driver are you using, should be a jar file,
do a listing of the jar file to see if Driver is in there,
'jar -tvf jarfile'

I'm using postgresql-8.0-310.jdbc3.jar

hth,

Luke
>
> public class Example1
> >>>{
> >>>public static void main(String[] argv)
> >>>{
> >>>    System.out.println("Checking if Driver is registerd");
> >>>    try
> >>>    {
> >>>    Class.forName("org.postgresql.Driver");
> >>>    }
> >>>    catch(ClassNotFoundException cnfe)
> >>>    {
> >>>    System.out.println("Couldn't find the Driver");
> >>>    cnfe.printStackTrace();
> >>>    System.exit(1);
> >>>    }
> >>>    System.out.println("registered the Driver OK, so lets make a
> >>>connection");
> >>>    Connection c = null;
> >>>
> >>>    try
> >>>    {
> >>>    c=
> >>>DriverManager.getConnection("jdbc:postgresql://localhost/trainneedcorp","postgres","admin");
> >>>    }
> >>>    catch(SQLException se)
> >>>    {
> >>>    System.out.println("Couldnt connect");
> >>>    se.printStackTrace();
> >>>    System.exit(1);
> >>>    }
> >>>    if(c != null)
> >>>    System.out.println("WE CONNECTED");
> >>>    else
> >>>    System.out.println("Reaching here is not done");
> >>>    }
> >>>    }
>
> >>>    I get the following error:
> >>>
> >>>java.lang.ClassNotFoundException: org.postgresql.Driver
> >>>        at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
> >>>        at java.security.AccessController.doPrivileged(Native Method)
> >>>        at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
> >>>        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
> >>>        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
> >>>        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
> >>>        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
> >>>        at java.lang.Class.forName0(Native Method)
> >>>        at java.lang.Class.forName(Class.java
>
> Am I going wrong anywhere??
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

--
............._..
.|  .| |.|/.|_ .
.|__.|_|.|\.|_ .
:61 421 276 282:

Re: JDBC Connectivity..

От
Dave Cramer
Дата:
Minal,

Don't bother building it, just download it from jdbc.postgresql.org.

Dave

On 20-Jun-05, at 2:28 AM, Minal wrote:

> I am noting down the steps..which I performed during installation
> and for using JDBC....
> 1. DO we have to use ./configure with-java ?
> because when I use that I get error that it failed. Is this the
> reason I am not able to eshtablish the connectivity...
> In  O'reily book it is mentioned that we have to build the
> driver...How does one do that??
> I have copied the postgresql driver in /usr/local/tomcat/common/lib
> directory..
> also set the class path...restarted the tomcat and used the java
> file as shown below...
>
> public class Example1
>
>> >>{
>> >>public static void main(String[] argv)
>> >>{
>> >>    System.out.println("Checking if Driver is registerd");
>> >>    try
>> >>    {
>> >>    Class.forName("org.postgresql.Driver");
>> >>    }
>> >>    catch(ClassNotFoundException cnfe)
>> >>    {
>> >>    System.out.println("Couldn't find the Driver");
>> >>    cnfe.printStackTrace();
>> >>    System.exit(1);
>> >>    }
>> >>    System.out.println("registered the Driver OK, so lets make a
>> >>connection");
>> >>    Connection c = null;
>> >>   >>    try
>> >>    {
>> >>    c= >>DriverManager.getConnection("jdbc:postgresql://
>> localhost/trainneedcorp","postgres","admin");
>> >>    }
>> >>    catch(SQLException se)
>> >>    {
>> >>    System.out.println("Couldnt connect");
>> >>    se.printStackTrace();
>> >>    System.exit(1);
>> >>    }
>> >>    if(c != null)
>> >>    System.out.println("WE CONNECTED");
>> >>    else
>> >>    System.out.println("Reaching here is not done");
>> >>    }
>> >>    }
>>
>
>
>> >>    I get the following error:
>> >>
>> >>java.lang.ClassNotFoundException: org.postgresql.Driver
>> >>        at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
>> >>        at java.security.AccessController.doPrivileged(Native
>> Method)
>> >>        at java.net.URLClassLoader.findClass(URLClassLoader.java:
>> 187)
>> >>        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
>> >>        at sun.misc.Launcher$AppClassLoader.loadClass
>> (Launcher.java:274)
>> >>        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
>> >>        at java.lang.ClassLoader.loadClassInternal
>> (ClassLoader.java:302)
>> >>        at java.lang.Class.forName0(Native Method)
>> >>        at java.lang.Class.forName(Class.java
>>
>
> Am I going wrong anywhere??
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
>
>



Dave Cramer
davec@postgresintl.com
www.postgresintl.com
ICQ #14675561
jabber davecramer@jabber.org
ph (519 939 0336 )