Re: Something unusual has occured to cause the driver to fail. NullPointerException

Поиск
Список
Период
Сортировка
От Barry Lind
Тема Re: Something unusual has occured to cause the driver to fail. NullPointerException
Дата
Msg-id 3B9C1B8D.4020903@xythos.com
обсуждение исходный текст
Ответ на Something unusual has occured to cause the driver to fail. NullPointerException  (Larry Rogers <larry@lwrogersjr.org>)
Список pgsql-jdbc
Larry,

Shouldn't your connection URL be:

jdbc:postgresql://localhost:5432/testdb

instead of

jdbc:postgresql://localhost:5432?database=testdb


thanks,
--Barry


Larry Rogers wrote:
> Hi all,
>
> I'm having trouble opening a database connection to a test database on a
> fresh PostGreSQL 7.1.3 installation on RedHat 7.1 from the RPMs.  I have a
> simple test class TestPostGreSQL that opens a connection, queries for all the
> rows in a table and prints the results to standard output.  The driver file
> is in the same directory as the java class, which I execute using
>
> java -classpath .:jdbc7.1-1.2.jar TestPostGreSQL
>
> I get the following error message:
>
> Something unusual has occured to cause the driver to fail. Please report this
> exception: Exception: java.lang.NullPointerException
> Stack Trace:
> java.lang.NullPointerException
>     at org.postgresql.Connection.openConnection(Connection.java:148)
>     at org.postgresql.Driver.connect(Driver.java:122)
>     at java.sql.DriverManager.getConnection(DriverManager.java:517)
>     at java.sql.DriverManager.getConnection(DriverManager.java:177)
>     at TestPostGreSQL.main(TestPostGreSQL.java:17)
> End of Stack Trace
>
> I created the database using
>
> createdb testdb
>
> and from psql created the table as
>
> create table Person (
> FirstName char(30) not null,
> LastName char(30) not null);
>
> then created the user and password and granted all permissions on the Person
> table.
>
> I start the server with
>
> postmaster -i
>
> to get TCP/IP support.  The code for the test class is at the end of this
> message.  Note that everything is commented out except for loading the driver
> and opening a connection.  I have used JDBC successfully for months with
> Microsoft SQL Server, but I'm anxious to switch over to PostGreSQL!
>
> Thanks in advance for any help!
> Larry Rogers
>
> *****************************
>
> import java.sql.*;
> import java.util.Date;
>
> public class TestPostGreSQL {
>
>     public static void main(String[] args) {
>
>         final String driver = "org.postgresql.Driver";
>         final String url = "jdbc:postgresql://localhost:5432?database=testdb";
>         final String login = "TestUser";
>         final String password = "TestPass";
>         String sql = "SELECT * FROM Person";
>
>         try {
>             Class.forName(driver);
>             Connection connection
>                 = DriverManager.getConnection(url, login, password);
>             /*
>
>             Statement statement = connection.createStatement();
>             ResultSet result = statement.executeQuery(sql);
>
>             while (result.next()) {
>                 System.out.println(result.getString("FirstName") + " " +
> result.getString("LastName"));
>             }
>             result.close();
>             statement.close();
>             */
>             connection.close();
>
>         } catch(SQLException e) {
>             System.out.println(e);
>         } catch(ClassNotFoundException e) {
>             System.out.println(e);
>         }
>     }
> }
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>
>



В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Larry Rogers
Дата:
Сообщение: Re: Something unusual has occured to cause the driver to fail. NullPointerException
Следующее
От: Barry Lind
Дата:
Сообщение: Re: [HACKERS] Troubles using German Umlauts with JDBC