I'm in a unix environment, using postgresql to supply data through a java servlet to a web-page.
I'm having problems getting the postgresql driver to load. I keep getting this error, "java.lang.ClassNotFoundException: No ClassLoaders found for: org.postgresql.Driver"
Here is the java code that I'm using:
import java.net.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Books extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
// defining my strings
String genre, author, query, username = "", password = "";
// getting data from my web-page
res.setContentType("text/html");
PrintWriter out = res.getWriter();
genre = req.getParameter("genre");
try
{
// connecting to the database
String url = "jdbcostgresql:testdb";
Class.forName("org.postgresql.Driver");
Connection db_connection = DriverManager.getConnection (url, username, password);
// creating the query statement
Statement db_statement = db_connection.createStatement();
query = "SELECT * FROM books";
ResultSet result = db_statement.executeQuery(query);
// formatting the output
out.println("<html>");
out.println("<head>");
out.println("<title>Welcome to Eric's Book Depository</title>");
out.println("</head>");
out.println("<body>");
out.println("<center>");
while(result.next())
{
out.println(result.getString("BookName") + "<br>");
}
db_statement.close();
db_connection.close();
out.println("</center>");
out.println("</body>");
out.println("</html>");
}
catch (ClassNotFoundException cnfe) // driver not found
{
out.println("<html>");
out.println("<head><title>Error Log</title></head>");
out.println("<body>");
out.println ("Unable to load database driver" + "<br>");
out.println ("Details : " + cnfe);
out.println("</body></html>");
}
catch (java.sql.SQLException sqle)
{
out.println("<html>");
out.println("<head><title>Error Log</title></head>");
out.println("<body>");
out.println("Error with SQL statements: " + sqle +"<br>");
out.println("</body></html>");
}
}
}
I'm using this in a shared environment, with TOMCAT as the application server deployed through JBOSS 3-2-3. I'm assuming that the database was installed and configured correctly, becuase I was able to create a table, and add the fields that I needed.
Please Help,
Growler
I'm having problems getting the postgresql driver to load. I keep getting this error, "java.lang.ClassNotFoundException: No ClassLoaders found for: org.postgresql.Driver"
Here is the java code that I'm using:
import java.net.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Books extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
// defining my strings
String genre, author, query, username = "", password = "";
// getting data from my web-page
res.setContentType("text/html");
PrintWriter out = res.getWriter();
genre = req.getParameter("genre");
try
{
// connecting to the database
String url = "jdbcostgresql:testdb";
Class.forName("org.postgresql.Driver");
Connection db_connection = DriverManager.getConnection (url, username, password);
// creating the query statement
Statement db_statement = db_connection.createStatement();
query = "SELECT * FROM books";
ResultSet result = db_statement.executeQuery(query);
// formatting the output
out.println("<html>");
out.println("<head>");
out.println("<title>Welcome to Eric's Book Depository</title>");
out.println("</head>");
out.println("<body>");
out.println("<center>");
while(result.next())
{
out.println(result.getString("BookName") + "<br>");
}
db_statement.close();
db_connection.close();
out.println("</center>");
out.println("</body>");
out.println("</html>");
}
catch (ClassNotFoundException cnfe) // driver not found
{
out.println("<html>");
out.println("<head><title>Error Log</title></head>");
out.println("<body>");
out.println ("Unable to load database driver" + "<br>");
out.println ("Details : " + cnfe);
out.println("</body></html>");
}
catch (java.sql.SQLException sqle)
{
out.println("<html>");
out.println("<head><title>Error Log</title></head>");
out.println("<body>");
out.println("Error with SQL statements: " + sqle +"<br>");
out.println("</body></html>");
}
}
}
I'm using this in a shared environment, with TOMCAT as the application server deployed through JBOSS 3-2-3. I'm assuming that the database was installed and configured correctly, becuase I was able to create a table, and add the fields that I needed.
Please Help,
Growler