i am facing some problems with the following code.
initially the jdbc driver(jdbc 4/3) ws not getting registered...nw somehw that problem has been rectified.bt nw i m unable to connect with the database(PostgreSQL).

The code i have written is as follows

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;


public class Example1 {
  public static void main(String[] argv) {
  System.out.println("Checking if Driver is registered
with DriverManager.");

  try {
    Class.forName("org.postgresql.Driver");
  } catch (ClassNotFoundException cnfe) {
    System.out.println("Couldn't find the driver!");
    System.out.println("Let's print a stack trace, and
exit.");
    cnfe.printStackTrace();
    System.exit(1);
  }

  System.out.println("Registered the driver ok, so
let's make a connection.");

  Connection c = null;

  try {
    // The second and third arguments are the username
and password,
    // respectively. They should be whatever is
necessary to connect
    // to the database.
    c =
DriverManager.getConnection("jdbc:postgresql://localhost/ids","postgres","123456");

  } catch (SQLException se) {
    System.out.println("Couldn't connect: print out a
stack trace and exit.");
    se.printStackTrace();
    System.exit(1);
  }

  if (c != null)
    System.out.println("Hooray! We connected to the
database!");
  else
    System.out.println("We should never get here.");
  }
}
*****************************************************
*****************************************************

The error that im geting is

*****************************************************
Checking if Driver is registered with DriverManager.
Registered the driver ok, so let's make a connection.
Couldn't connect: print out a stack trace and exit.
org.postgresql.util.PSQLException: A connection error
has occurred: org.postgresql.util.PSQLException:
FATAL: Ident authentication failed for user "postgres"

  at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnectionV3(AbstractJdbc1Connection.java:337)
  at
org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:214)
  at org.postgresql.Driver.connect(Driver.java:139)
  at
java.sql.DriverManager.getConnection(libgcj.so.7rh)
  at
java.sql.DriverManager.getConnection(libgcj.so.7rh)
  at Example1.main(Example1.java:27)
******************************************************

kindly help me with this.... my final yr project
is stuck up because of this...
looking forward to your reply

parul

What it looks like is, either the user "postgres" doesn't exist in the DB, or the provided password is wrong.

Edit:

Or the provided user does not have permission to access the Tablespace/SID/whatever_it_is_called_in_PostGreSQL requested in the URL (the part after localhost).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.