Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have configured apache tomcat in ubuntu. I am using postgresql as database. I have downloaded postgresql-9.3-1101.jdbc3.jar connector and set CLASSPATH as follows:

export CLASSPATH=/var/lib/tomcat7/webapps/CMAS/WEB_INF/lib/postgresql-9.3-1101.jdbc3.jar

I am using a JSP program to access Database values, code as follows:

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.* " %>
<%@ page import="java.io.*" %>
<%
try {
String driver = "org.postgresql.Driver";
String url = "jdbc:postgresql://localhost:5432/CMAS";
String username = "postgres";
String password = "postgres";

String myDataField = null;
String myQuery = "SELECT * FROM survey_details";
Connection myConnection = null;
PreparedStatement myPreparedStatement = null;
ResultSet myResultSet = null;
Class.forName(driver).newInstance();
myConnection = DriverManager.getConnection(url,username,password);
myPreparedStatement = myConnection.prepareStatement(myQuery);
myResultSet = myPreparedStatement.executeQuery();
if(myResultSet.next()){
out.print("herezz");
myDataField = myResultSet.getString("imei");
out.print(myDataField);
}
}
catch(Exception e){
out.print(e);
}

%>

I am getting an exception "java.lang.ClassNotFoundException: org.postgresql.Driver". I understand its because of classpath. But how can I fix this?

share|improve this question
    
@CraigRinger then what must be the reason for java.lang.ClassNotFoundException: org.postgresql.Driver Exception. I am new to ubuntu –  androidsuckzzz Apr 25 at 5:54
    
Because you haven't installed the JDBC Driver in tomcat. google.com/search?q=tomcat+install+jdbc+driver, stackoverflow.com/q/13860024/398670 –  Craig Ringer Apr 25 at 6:30
1  
Try this link: stackoverflow.com/questions/9329650/java-classpath-linux This will help you. –  user1365067 Apr 28 at 5:52

1 Answer 1

The tomcat server does not have the postgresql JDBC driver in its resources.

Copy the postgresql-xxxx.Jar file to "apache-tomcat-xxxx\lib" folder.

(xxxx = whatever version you are using)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.