Обсуждение: JDBC in Red hat 9

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

JDBC in Red hat 9

От
"Joseph Thomas"
Дата:
<div style="background-color:"><div>Ok I am new to Linux, so please bear with me. I am running Red Hat 9 that comes
withPostgreSQL7.3.2-3. </div><div> </div><div>I have created a "test" database and am trying to access it using a java
programthrough jdbc. </div><div>I am recieving and error: "Exception! java.lang.ClassNotFoundException:
postgresql.Driver"</div><div> </div><div>Ihave my CLASSPATH set to point to pg73b1jdbc1.jar, pg73b1jdbc2.jar and
pg73b1jdbc3.jar.</div><div> </div><div>Iam reading a HOW TO for jdbc and PostgreSQL From <a
href="http://tldp.org/HOWTO/Enterprise-Java-for-Linux-HOWTO-6.html">http://tldp.org/HOWTO/Enterprise-Java-for-Linux-HOWTO-6.html</a>
butthis is for version 6.5, do I need to do anything else?</div><div> </div><div>here is my java code:</div><div>import
java.sql.*;<br/><br />class PostgreSQLTest {<br />  public static void main (String[] args) {<br />    try {<br />     
Driverdriver = (Driver)<br />        Class.forName("postgresql.Driver").newInstance();<br />     
DriverManager.registerDriver(driver);<br/><br />      String     url = "jdbc:postgresql:javatest"; <br />     
Connectioncon = DriverManager.getConnection(url, "postgres", ""); <br />      Statement  stm = con.createStatement();
<br/><br />      stm.setQueryTimeout(10); <br />      ResultSet  rs  = stm.executeQuery("select col1 from test"); <br
/><br/>      rs.next(); <br /><br />      System.out.println(rs.getString(1)); <br /><br />    } catch (SQLExcept ion
e){ <br /><br />      System.out.println("Exception!"); <br />      System.out.println(e.toString()); <br />  } <br />}
<br/></div></div><br clear="all" /><hr />Tired of spam? Get <a href="http://g.msn.com/8HMLENUS/2734??PS=">advanced junk
mailprotection</a> with MSN 8. 

Re: JDBC in Red hat 9

От
Barry Lind
Дата:
Joseph,

Two things wrong that I can see:

1) The driver class is now org.postgresql.Driver (not postgresql.Driver)
2) You only include one of the jar files in the classpath (the one that
corresponds to the version of java/jdbc you are running: jdbc1 = jdk1.1,
jdbc2= jdk1.2 and 1.3, jdbc3= jdk1.4

thanks,
--Barry


Joseph Thomas wrote:
> Ok I am new to Linux, so please bear with me. I am running Red Hat 9
> that comes with PostgreSQL7.3.2-3.
>
> I have created a "test" database and am trying to access it using a java
> program through jdbc.
> I am recieving and error: "Exception! java.lang.ClassNotFoundException:
> postgresql.Driver"
>
> I have my CLASSPATH set to point to pg73b1jdbc1.jar, pg73b1jdbc2.jar and
> pg73b1jdbc3.jar.
>
> I am reading a HOW TO for jdbc and PostgreSQL From
> http://tldp.org/HOWTO/Enterprise-Java-for-Linux-HOWTO-6.html but this is
> for version 6.5, do I need to do anything else?
>
> here is my java code:
> import java.sql.*;
>
> class PostgreSQLTest {
>   public static void main (String[] args) {
>     try {
>       Driver driver = (Driver)
>         Class.forName("postgresql.Driver").newInstance();
>       DriverManager.registerDriver(driver);
>
>       String     url = "jdbc:postgresql:javatest";
>       Connection con = DriverManager.getConnection(url, "postgres", "");
>       Statement  stm = con.createStatement();
>
>       stm.setQueryTimeout(10);
>       ResultSet  rs  = stm.executeQuery("select col1 from test");
>
>       rs.next();
>
>       System.out.println(rs.getString(1));
>
>     } catch (SQLExcept ion e) {
>
>       System.out.println("Exception!");
>       System.out.println(e.toString());
>   }
> }
>
> ------------------------------------------------------------------------
> Tired of spam? Get advanced junk mail protection
> <http://g.msn.com/8HMLENUS/2734??PS=> with MSN 8.



Re: JDBC in Red hat 9

От
"Joseph Thomas"
Дата:
<div style="background-color:"><div><p>ok, <p>I updated the CLASSPATH to have pgb1jdbc2.jar, and modfied my code to say
"Class.forName("org.postgresql.Driver").newInstance();"<p>but I am still getting the error "Exception!
java.lang.ClassNotFoundException:org.postgresql.Driver" <br /><br /></div><div></div>----Original Message Follows----
<div></div>From:Barry Lind  <div></div>To: Joseph Thomas  <div></div>CC: pgsql-jdbc@postgresql.org <div></div>Subject:
Re:[JDBC] JDBC in Red hat 9 <div></div>Date: Wed, 28 May 2003 21:58:02 -0700 <div></div><div></div>Joseph,
<div></div><div></div>Twothings wrong that I can see: <div></div><div></div>1) The driver class is now
org.postgresql.Driver(not postgresql.Driver) <div></div>2) You only include one of the jar files in the classpath (the
onethat corresponds to the version of java/jdbc you are running: jdbc1 = jdk1.1, jdbc2= jdk1.2 and 1.3, jdbc3= jdk1.4
<div></div><div></div>thanks,<div></div>--Barry <div></div><div></div><div></div>Joseph Thomas wrote: <div></div>>Ok
Iam new to Linux, so please bear with me. I am running Red Hat 9 <div></div>>that comes with PostgreSQL7.3.2-3.
<div></div>>I have created a "test" database and am trying to access it using <div></div>>a java program through
jdbc.<div></div>>I am recieving and error: "Exception! <div></div>>java.lang.ClassNotFoundException:
postgresql.Driver"<div></div>> I have my CLASSPATH set to point to pg73b1jdbc1.jar, <div></div>>pg73b1jdbc2.jar
andpg73b1jdbc3.jar. <div></div>> I am reading a HOW TO for jdbc and PostgreSQL From
<div></div>>http://tldp.org/HOWTO/Enterprise-Java-for-Linux-HOWTO-6.htmlbut <div></div>>this is for version 6.5,
doI need to do anything else? <div></div>> here is my java code: <div></div>>import java.sql.*; <div></div>>
<div></div>>classPostgreSQLTest { <div></div>> public static void main (String[] args) { <div></div>> try {
<div></div>>Driver driver = (Driver) <div></div>> Class.forName("postgresql.Driver").newInstance();
<div></div>>DriverManager.registerDriver(driver); <div></div>> <div></div>> String url =
"jdbc:postgresql:javatest";<div></div>> Connection con = DriverManager.getConnection(url, "postgres",
<div></div>>"");<div></div>> Statement stm = con.createStatement(); <div></div>> <div></div>>
stm.setQueryTimeout(10);<div></div>> ResultSet rs = stm.executeQuery("select col1 from test"); <div></div>>
<div></div>>rs.next(); <div></div>> <div></div>> System.out.println(rs.getString(1)); <div></div>>
<div></div>>} catch (SQLExcept ion e) { <div></div>> <div></div>> System.out.println("Exception!");
<div></div>>System.out.println(e.toString()); <div></div>> } <div></div>>} <div></div>>
<div></div>>------------------------------------------------------------------------<div></div>>Tired of spam?
Getadvanced junk mail protection <div></div>> with MSN 8.
<div></div><div></div><div></div><div></div>---------------------------(endof broadcast)---------------------------
<div></div>TIP5: Have you checked our extensive FAQ? <div></div><div></div>http://www.postgresql.org/docs/faqs/FAQ.html
<div></div></div><brclear="all" /><hr />Tired of spam? Get <a href="http://g.msn.com/8HMHENUS/2734??PS=">advanced junk
mailprotection</a> with MSN 8.