Обсуждение: "No Suitable Driver"
Hi, I'm trying to get a small test program going. I have built PostgreSQL
7.1.3 on RedHat 6.2 with --java, installed and created databases, verified
with psql. The postgresql.jar is on my classpath.
My pg_hba.conf has:
local all password
host all 127.0.0.1 255.255.255.255 password
Here is my code:
import java.sql.*;
public class PostgresTest {
public static void main(String[] args) {
try {
Connection db =
DriverManager.getConnection("jdbc.postgresql:test&user=test&password=test");
// I've also tried all the permutations of getConnection() and urls.
// db, user, and password names have been changed to protect the innocent
// I've also tried Class.forName("org.postgresql.Driver") and
// Class.forName("org.postgresql.Driver").newInstance() instead of the arg.
db.close();
} catch(Throwable t) {
t.printStackTrace(System.out);
}
}
}
--
Running it with:
java -Djdbc.drivers=org.postgresql.Driver PostgresTest
where the db has been started by user postgres with:
/usr/local/pgsql/bin/postmaster -i -D /data/pgsql >/data/pgsql/pgsql.log 2>&1 &
And the error is:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:537)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at PostgresTest.main(PostgresTest.java:6)
What is wrong?
--
Guy McArthur * email{guym@arizona.edu} http{guymcarthur.com}
You need to load the driver first and then get the connection, also the
url for the connection s/b
jdbc:postgresql://hostname/test&user=test&password=test"
Assuming your database name is test
So your code needs to execute
Class.forName("org.postgresql.Driver")
And then
Connection db =
DriverManager.getConnection("jdbc:postgresql://hostname/test"test",test"
);
Dave
-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Guy McArthur
Sent: October 24, 2001 7:13 PM
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] "No Suitable Driver"
Hi, I'm trying to get a small test program going. I have built
PostgreSQL 7.1.3 on RedHat 6.2 with --java, installed and created
databases, verified with psql. The postgresql.jar is on my classpath.
My pg_hba.conf has:
local all password
host all 127.0.0.1 255.255.255.255 password
Here is my code:
import java.sql.*;
public class PostgresTest {
public static void main(String[] args) {
try {
Connection db =
DriverManager.getConnection("jdbc.postgresql:test&user=test&password=tes
t");
// I've also tried all the permutations of getConnection() and urls. //
db, user, and password names have been changed to protect the innocent
// I've also tried Class.forName("org.postgresql.Driver") and //
Class.forName("org.postgresql.Driver").newInstance() instead of the arg.
db.close();
} catch(Throwable t) {
t.printStackTrace(System.out);
}
}
}
--
Running it with:
java -Djdbc.drivers=org.postgresql.Driver PostgresTest
where the db has been started by user postgres with:
/usr/local/pgsql/bin/postmaster -i -D /data/pgsql >/data/pgsql/pgsql.log
2>&1 &
And the error is:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:537)
at java.sql.DriverManager.getConnection(DriverManager.java:199)
at PostgresTest.main(PostgresTest.java:6)
What is wrong?
--
Guy McArthur * email{guym@arizona.edu} http{guymcarthur.com}
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
http://archives.postgresql.org
Guy, Send me the pertinent code where you are loading the driver Dave -----Original Message----- From: Guy McArthur [mailto:guym@arizona.edu] Sent: October 25, 2001 6:28 PM To: Dave Cramer Cc: pgsql-jdbc@postgresql.org Subject: RE: [JDBC] "No Suitable Driver" Huh. Well I have set up Jive Forums 2.1.1 (jivesoftware.com) using postgres jdbc and it seems to work fine. Also in the Resin java web-app server I set up a DataSource pool of postgres connections, and that seems to work fine, fetching a connection, doing a query and all that. I haven't looked at the source to see how they are doing it. But it absolutely does not work from my command-line test app no matter which way I've tried it.
Huh. Well I have set up Jive Forums 2.1.1 (jivesoftware.com) using postgres jdbc and it seems to work fine. Also in the Resin java web-app server I set up a DataSource pool of postgres connections, and that seems to work fine, fetching a connection, doing a query and all that. I haven't looked at the source to see how they are doing it. But it absolutely does not work from my command-line test app no matter which way I've tried it.
Guy-
I just looked back at your original post-
Have you tried a getConnection call that looks like this:
DriverManager.getConnection("jdbc.postgresql:test,"test","test");
-Nick
--------------------------------------------------------------------------
Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788
Ray Ontko & Co. Software Consulting Services http://www.ontko.com/
> Have you tried a getConnection call that looks like this:
>
> DriverManager.getConnection("jdbc.postgresql:test,"test","test");
^^^
that was my mistake.
>
> I just looked back at your original post-
>
> Have you tried a getConnection call that looks like this:
>
> DriverManager.getConnection("jdbc.postgresql:test,"test","test");
^
that was my mistake.