Is the postgres jar locate somewhere the app have access to? Good
places are: commons/lib in $CATALINA_BASE or WEB-INF/lib in the
application directory.
Saludos
>>>>> "Luke" == Luke Vanderfluit <[EMAIL PROTECTED]> writes:
Luke> Hi, I'm having a few probs (fun) getting jdbc to work in
Luke> servlets and jsp, tomcat in other words.
Luke> I've successfully got jdbc working with postgresql in a regular
Luke> java class.
Luke> I have tried using the same code adapted to a servlet and jsp
Luke> to get a database connection happening from there, however no
Luke> luck,
Luke> Is there anything I need to set up in server.xml or web.xml
Luke> before it can work?
Luke> here is my jsp and servlet code:
Luke> ################################ jsp file -=-=-=-= <html>
Luke> <head> </head> <%@ page language="java" import="java.sql.*" %>
Luke> <body> <%
Luke> Class.forName("org.postgresql.Driver"); Connection
Luke> myConn=DriverManager.getConnection("jdbc:postgresql:mboard",
Luke> "luke", "");
Luke> %> </body> </html> =-=-=-=-=-=-=-=-=-=-=-=-=-= servlet code
Luke> =-=-=-=-=-=-=-=-=-=-=-=-=-= import javax.servlet.*; import
Luke> javax.servlet.http.*; import java.io.*; import java.sql.*;
Luke> import java.text.DateFormat;
Luke> /** * ShowEmployees creates an HTML table containing a list of
Luke> all * employees (sorted by last name) and the departments to
Luke> which * they belong. */ public class ShowEmployees extends
Luke> HttpServlet { Connection dbConn = null;
Luke> /** * Establishes a connection to the database. */ public
Luke> void init() throws ServletException { String jdbcDriver =
Luke> "org.postgresql.Driver"; String dbURL =
Luke> "\"jdbc:postgresql:mboard\", \"luke\", \"\"";
Luke> try { Class.forName("org.postgresql.Driver").newInstance();
Luke> //load driver dbConn =
Luke> DriverManager.getConnection("jdbc:postgresql:megaboard",
Luke> "luke", ""); //connect } catch (ClassNotFoundException e) {
Luke> throw new UnavailableException("JDBC driver not found:" +
Luke> jdbcDriver); } catch (SQLException e) { throw new
Luke> UnavailableException("Unable to connect to: " + dbURL); } catch
Luke> (Exception e) { throw new UnavailableException("Error: " + e);
Luke> } }
Luke> /** * Displays the employees table. */ public void
Luke> service(HttpServletRequest request, HttpServletResponse
Luke> response) throws ServletException, IOException {
Luke> response.setContentType("text/html");
Luke> PrintWriter out = response.getWriter();
Luke> try { //join EMPLOYEE and DEPARTMENT tables to get all data
Luke> String sql = "select * from message;";
Luke> Statement stmt = dbConn.createStatement(); ResultSet rs =
Luke> stmt.executeQuery(sql);
Luke> out.println("<HTML>"); out.println("<HEAD><TITLE>Show
Luke> Employees</TITLE></HEAD>"); out.println("<BODY>");
Luke> out.println("<TABLE BORDER=\"1\" CELLPADDING=\"3\">");
Luke> out.println("<TR>"); out.println("<TH>Name</TH>");
Luke> out.println("<TH>Department</TH>");
Luke> out.println("<TH>Phone</TH>"); out.println("<TH>Email</TH>");
Luke> out.println("<TH>Hire Date</TH>"); out.println("</TR>");
Luke> while (rs.next()) { out.println("<TR>");
Luke> out.println("<TD>" + rs.getString("resusername") +
Luke> "</td>");
Luke> out.println("</TR>"); }
Luke> out.println("</TABLE>"); out.println("</BODY></HTML>");
Luke> rs.close(); stmt.close(); } catch (SQLException e) {
Luke> out.println("<H2>Database currently unavailable.</H2>"); }
Luke> out.close(); } }
Luke> any help would be greatly appreciated. thanks, kind regards
Luke> Luke
Luke> --
Luke> ==================================== "when my computer smiles,
Luke> I'm happy" ===============================.~ ~, Luke
Luke> Vanderfluit |'/'] Mobile: 0421 276 282 \~/`
Luke> ---------------------------------------------------------------------
Luke> To unsubscribe, e-mail:
Luke> [EMAIL PROTECTED] For additional
Luke> commands, e-mail: [EMAIL PROTECTED]
--
+-----------------
| Francisco Vides Fern�ndez <[EMAIL PROTECTED]>
| Director t�cnico.
| Tel�fono fijo: 952 60 29 59
| Tel�fono m�vil: 661 67 32 73
| Fax: 952 60 29 59
| D�dalo Ingenieros http://www.dedaloingenieros.com/
| PGP: http://pgp.rediris.es:11371/pks/lookup?op=index&search=0x5AAE6285
+------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]