0

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?

3

1 Answer 1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.