Connection problem
Connection problem
От:
Ripon Al Wasim <riponc007@yahoo.com>
Дата:
hello,
I wanna connet between java and PostgreSQL. Here is the code:
import java.sql.*;
public class DBConnection
{
{
public void connection()
{
String pgsqlDriver = "org.postgresql.Driver";
//String pgsqlURL = "jdbc:postgresql://host:5432/mydb";
String pgsqlURL = "jdbc:postgresql://192.168.0.165/testdb";
{
String pgsqlDriver = "org.postgresql.Driver";
//String pgsqlURL = "jdbc:postgresql://host:5432/mydb";
String pgsqlURL = "jdbc:postgresql://192.168.0.165/testdb";
String pgsqlUser = "User";
String pgsqlPW = "password";
String pgsqlQuery = null;
Connection pgsqlConn = null;
Statement pgsqlStatement = null;
ResultSet pgsqlRSet = null;
String pgsqlPW = "password";
String pgsqlQuery = null;
Connection pgsqlConn = null;
Statement pgsqlStatement = null;
ResultSet pgsqlRSet = null;
try
{
Class.forName(pgsqlDriver);
pgsqlConn = DriverManager.getConnection(pgsqlURL, pgsqlUser, pgsqlPW);
pgsqlStatement = pgsqlConn.createStatement();
pgsqlQuery = "SELECT * FROM users;";
pgsqlRSet = pgsqlStatement.executeQuery(pgsqlQuery);
}
{
Class.forName(pgsqlDriver);
pgsqlConn = DriverManager.getConnection(pgsqlURL, pgsqlUser, pgsqlPW);
pgsqlStatement = pgsqlConn.createStatement();
pgsqlQuery = "SELECT * FROM users;";
pgsqlRSet = pgsqlStatement.executeQuery(pgsqlQuery);
}
catch (ClassNotFoundException cnfe)
{
System.out.println("Could not load database driver:" + cnfe.getMessage());
}
{
System.out.println("Could not load database driver:" + cnfe.getMessage());
}
catch (SQLException sqle)
{
System.out.println("Could not connect to the database: " + sqle.getMessage());
}
{
System.out.println("Could not connect to the database: " + sqle.getMessage());
}
finally
{
{
try
{
if ( pgsqlConn != null )
{
// Close the connection no matter what.
pgsqlConn.close();
}
}
{
if ( pgsqlConn != null )
{
// Close the connection no matter what.
pgsqlConn.close();
}
}
catch (SQLException sqle)
{
System.out.println("Could not connect to the database(2): " + sqle.getMessage());
}
}//finally
}//end connection()
{
System.out.println("Could not connect to the database(2): " + sqle.getMessage());
}
}//finally
}//end connection()
public static void main(String args[])
{
new DBConnection().connection();
}
}//class
{
new DBConnection().connection();
}
}//class
The code is compile well. But here is a runtime problem. The prolem is:
Could not load database driver :org.postgresql.Driver
Is there anybody to help me?
thanking u,
Ripon
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
Re: Connection problem
От:
Kris Jurka <books@ejurka.com>
Дата:
On Sun, 3 Aug 2003, Ripon Al Wasim wrote: > The code is compile well. But here is a runtime problem. The prolem is: > > Could not load database driver :org.postgresql.Driver > It looks like you do not have the postgresql jdbc driver in your CLASSPATH. Kris Jurka
Re: Connection problem
Do you have the appropriate postgres jar in your class path? Original message attached.
Re: Connection problem
От:
Erik Price <eprice@ptc.com>
Дата:
Ripon Al Wasim wrote: > The code is compile well. But here is a runtime problem. The prolem is: > > Could not load database driver :org.postgresql.Driver Note that the PostgreSQL driver JAR file must be in your $CLASSPATH or %CLASSPATH%. This means not just in a directory that is in your CLASSPATH (like with package directories or class files), but the CLASSPATH must actually explicitly list the location of the PostgreSQL driver JAR file. Erik