Results 1 to 1 of 1
- 11-06-2011, 12:18 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 1
- Rep Power
- 0
Need help with error: java.lang.ClassNotFoundException: org.postgresql.Driver
Hi,
I'm doing a project where I need to use a postgres database, and I'm trying to connect to the database but apparently the driver is not visible to the project. This is an extremely weird problem, because I had previously configured another project just like the one I'm doing now as an example, and it could connect to the database using almost the exact same code. I have tried going to Project->Properties->Java Build Path->Libraries->Add External Jar and also Project->Properties->Java Build Path->Libraries->Add External Library to load the jdbc connector .jar, which worked the first time in the example project but will not work on my current project. I am totally stumped; I even tried modifying the MANIFEST.MF file to manually include the .jar in the classpath (by writing the location of the file there). Nothing has worked so far.
Here's my DataSource file, which makes the connection to the database. The problem seems to be line 15; it can't seem to find the driver.
Java Code:package dbproject.classes; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DataSource { private static DataSource singleton = null; private String userName; private String password; private String dbName; private DataSource(String userName, String password, String dbName) throws ClassNotFoundException { Class.forName("org.postgresql.Driver"); this.userName = userName; this.password = password; this.dbName = dbName; } public static DataSource getInstance() throws ClassNotFoundException { if (singleton == null){ singleton = new DataSource("postgres", "albertino16", "dbproject_OfficeSuppliesDB"); } return singleton; } public Connection getJDBCConnection() throws SQLException{ String dbURL = "jdbc:postgresql://localhost:5432/" + this.dbName; Connection dbConn = DriverManager.getConnection(dbURL, userName, password); return dbConn; } }
I would really appreciate if anyone could help me out!
Tino
Similar Threads
-
Error -- java.lang.ClassNotFoundException
By dewitrydan in forum New To JavaReplies: 18Last Post: 03-02-2012, 04:25 PM -
java.lang.ClassNotFoundException: com.sun.star.lang.XEventListener
By Leroy in forum Advanced JavaReplies: 8Last Post: 11-04-2010, 01:46 PM -
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
By ljustiniano in forum New To JavaReplies: 6Last Post: 02-19-2010, 01:57 PM -
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
By kishan.java in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 10-19-2009, 05:34 PM -
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
By haneeshrawther in forum Advanced JavaReplies: 0Last Post: 03-21-2008, 01:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks